critical bug fixed + improvements
This commit is contained in:
+26
-10
@@ -2,17 +2,33 @@ import { prisma } from "@/lib/api/db";
|
||||
|
||||
export default async function getPermission(
|
||||
userId: number,
|
||||
collectionId: number
|
||||
collectionId: number,
|
||||
linkId?: number
|
||||
) {
|
||||
const check = await prisma.collection.findFirst({
|
||||
where: {
|
||||
AND: {
|
||||
id: collectionId,
|
||||
OR: [{ ownerId: userId }, { members: { some: { userId } } }],
|
||||
if (linkId) {
|
||||
const link = await prisma.link.findUnique({
|
||||
where: {
|
||||
id: linkId,
|
||||
},
|
||||
},
|
||||
include: { members: true },
|
||||
});
|
||||
include: {
|
||||
collection: {
|
||||
include: { members: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return check;
|
||||
return link;
|
||||
} else {
|
||||
const check = await prisma.collection.findFirst({
|
||||
where: {
|
||||
AND: {
|
||||
id: collectionId,
|
||||
OR: [{ ownerId: userId }, { members: { some: { userId } } }],
|
||||
},
|
||||
},
|
||||
include: { members: true },
|
||||
});
|
||||
|
||||
return check;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user