2023-02-18 21:32:02 -06:00
|
|
|
import { prisma } from "@/lib/api/db";
|
|
|
|
|
2023-06-09 17:31:14 -05:00
|
|
|
export default async function getCollection(userId: number) {
|
2023-02-18 21:32:02 -06:00
|
|
|
const collections = await prisma.collection.findMany({
|
|
|
|
where: {
|
2023-04-26 15:40:48 -05:00
|
|
|
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,
|
2023-10-27 23:45:14 -05:00
|
|
|
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
|
|
|
}
|