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

39 lines
723 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;
linkId?: number;
};
export default async function getPermission({
userId,
collectionId,
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;
} else if (collectionId) {
2023-06-24 16:54:35 -05:00
const check = await prisma.collection.findFirst({
where: {
2023-11-19 15:22:27 -06:00
id: collectionId,
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;
}
}