feat: ditch triplit, move to postgresql + drizzle orm
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { db } from "~~/server/lib/db";
|
||||
import * as z from 'zod';
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
await protectRoute(event);
|
||||
const userId = event.context.user!.id as string;
|
||||
|
||||
const result = await getValidatedQuery(event, z.object({
|
||||
page: z.number().optional(),
|
||||
limit: z.number().optional(),
|
||||
}).safeParse)
|
||||
|
||||
if (!result.success) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
message: result.error.issues[0]!.message,
|
||||
});
|
||||
}
|
||||
|
||||
const agents = await db.query.agents.findMany({
|
||||
where: {
|
||||
userId,
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'asc',
|
||||
},
|
||||
with: {
|
||||
topics: {
|
||||
orderBy: {
|
||||
createdAt: 'desc',
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return agents;
|
||||
})
|
||||
Reference in New Issue
Block a user