- Replaced Sequelize models with Drizzle ORM for app and app list management. - Updated routes in app-manager to utilize new database queries. - Removed obsolete Sequelize model files for app, app list, and app domain. - Introduced new helper functions for app and app domain management. - Enhanced user app management with improved file handling and user migration. - Adjusted public API routes to align with new database structure. - Implemented caching mechanisms for domain management.
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { app, db, schema } from '@/app.ts';
|
|
import { ConfigPermission } from '@kevisual/permission';
|
|
import { eq, desc, asc } from 'drizzle-orm';
|
|
|
|
// curl http://localhost:4005/api/router?path=app&key=public-list
|
|
// TODO:
|
|
app
|
|
.route({
|
|
path: 'app',
|
|
key: 'public-list',
|
|
})
|
|
.define(async (ctx) => {
|
|
const { username = 'root', status = 'running', page = 1, pageSize = 100, order = 'DESC' } = ctx.query.data || {};
|
|
const offset = (page - 1) * pageSize;
|
|
const apps = await db.select().from(schema.kvApp)
|
|
.where(eq(schema.kvApp.user, username))
|
|
.orderBy(order === 'DESC' ? desc(schema.kvApp.updatedAt) : asc(schema.kvApp.updatedAt))
|
|
.limit(pageSize)
|
|
.offset(offset);
|
|
// Note: Drizzle doesn't have a direct equivalent to findAndCountAll
|
|
// We need to do a separate count query
|
|
const countResult = await db.select({ count: schema.kvApp.id }).from(schema.kvApp)
|
|
.where(eq(schema.kvApp.user, username));
|
|
const count = countResult.length;
|
|
ctx.body = {
|
|
list: apps.map((item) => {
|
|
return ConfigPermission.getDataPublicPermission(item);
|
|
}),
|
|
pagination: {
|
|
total: count,
|
|
},
|
|
};
|
|
})
|
|
.addTo(app);
|