updated route + bug fixed

This commit is contained in:
daniel31x13
2023-11-19 16:22:27 -05:00
parent bd16136946
commit 0c6911aaf0
13 changed files with 98 additions and 103 deletions
+7 -25
View File
@@ -1,35 +1,24 @@
import { prisma } from "@/lib/api/db";
type Props = {
userId?: number;
userId: number;
collectionId?: number;
linkId?: number;
isPublic?: boolean;
};
export default async function getPermission({
userId,
collectionId,
linkId,
isPublic,
}: Props) {
if (linkId) {
const check = await prisma.collection.findFirst({
where: {
[isPublic ? "OR" : "AND"]: [
{
id: collectionId,
OR: [{ ownerId: userId }, { members: { some: { userId } } }],
links: {
some: {
id: linkId,
},
},
links: {
some: {
id: linkId,
},
{
isPublic: isPublic ? true : undefined,
},
],
},
},
include: { members: true },
});
@@ -38,15 +27,8 @@ export default async function getPermission({
} else if (collectionId) {
const check = await prisma.collection.findFirst({
where: {
[isPublic ? "OR" : "AND"]: [
{
id: collectionId,
OR: [{ ownerId: userId }, { members: { some: { userId } } }],
},
{
isPublic: isPublic ? true : undefined,
},
],
id: collectionId,
OR: [{ ownerId: userId }, { members: { some: { userId } } }],
},
include: { members: true },
});