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);