el.xwx.moe/lib/api/controllers/collections/getCollections.ts
2023-06-16 16:25:21 +03:30

30 lines
601 B
TypeScript

import { prisma } from "@/lib/api/db";
export default async function getCollection(userId: number) {
const collections = await prisma.collection.findMany({
where: {
OR: [
{ ownerId: userId },
{ members: { some: { user: { id: userId } } } },
],
},
include: {
_count: {
select: { links: true },
},
members: {
include: {
user: {
select: {
email: true,
name: true,
},
},
},
},
},
});
return { response: collections, status: 200 };
}