pstream-backend/server/routes/users/[id]/lists/index.get.ts
2025-04-02 21:04:46 -05:00

29 lines
593 B
TypeScript

import { useAuth } from "#imports";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
export default defineEventHandler(async (event) => {
const userId = event.context.params?.id;
const session = await useAuth().getCurrentSession();
if (session.user !== userId) {
throw createError({
statusCode: 403,
message: "Cannot access other user information",
});
}
const lists = await prisma.lists.findMany({
where: {
user_id: userId,
},
include: {
list_items: true,
},
});
return {
lists,
};
});