el.xwx.moe/lib/api/controllers/collections/getCollections.ts

37 lines
727 B
TypeScript
Raw Normal View History

2023-02-18 21:32:02 -06:00
import { prisma } from "@/lib/api/db";
export default async function getCollection(userId: number) {
2023-02-18 21:32:02 -06:00
const collections = await prisma.collection.findMany({
where: {
OR: [
{ ownerId: userId },
{ members: { some: { user: { id: userId } } } },
],
},
include: {
2023-06-16 07:55:21 -05:00
_count: {
select: { links: true },
},
2024-02-18 03:32:31 -06:00
parent: {
select: {
id: true,
name: true,
},
},
2023-04-27 18:13:21 -05:00
members: {
include: {
user: {
select: {
2023-07-08 05:35:43 -05:00
username: true,
2023-04-27 18:13:21 -05:00
name: true,
image: true,
2023-04-27 18:13:21 -05:00
},
},
},
},
2023-02-18 21:32:02 -06:00
},
});
2023-03-28 02:31:50 -05:00
return { response: collections, status: 200 };
2023-02-18 21:32:02 -06:00
}