el.xwx.moe/lib/api/getPermission.ts

42 lines
842 B
TypeScript
Raw Normal View History

import { prisma } from "@/lib/api/db";
type Props = {
2023-11-19 15:22:27 -06:00
userId: number;
collectionId?: number;
2024-02-14 07:10:45 -06:00
collectionName?: string;
linkId?: number;
};
export default async function getPermission({
userId,
collectionId,
2024-02-14 07:10:45 -06:00
collectionName,
linkId,
}: Props) {
2023-06-24 16:54:35 -05:00
if (linkId) {
const check = await prisma.collection.findFirst({
2023-06-24 16:54:35 -05:00
where: {
2023-11-19 15:22:27 -06:00
links: {
some: {
id: linkId,
},
2023-11-19 15:22:27 -06:00
},
2023-06-24 16:54:35 -05:00
},
include: { members: true },
2023-06-24 16:54:35 -05:00
});
return check;
2024-02-14 07:10:45 -06:00
} else if (collectionId || collectionName) {
2023-06-24 16:54:35 -05:00
const check = await prisma.collection.findFirst({
where: {
2024-02-14 07:10:45 -06:00
id: collectionId || undefined,
name: collectionName || undefined,
2023-11-19 15:22:27 -06:00
OR: [{ ownerId: userId }, { members: { some: { userId } } }],
2023-06-24 16:54:35 -05:00
},
include: { members: true },
});
2023-06-24 16:54:35 -05:00
return check;
}
}