finished the public page

This commit is contained in:
daniel31x13
2023-11-19 08:12:37 -05:00
parent b50ec09727
commit 614d92f050
21 changed files with 576 additions and 176 deletions
+25 -9
View File
@@ -1,24 +1,35 @@
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: {
links: {
some: {
id: linkId,
[isPublic ? "OR" : "AND"]: [
{
id: collectionId,
OR: [{ ownerId: userId }, { members: { some: { userId } } }],
links: {
some: {
id: linkId,
},
},
},
},
{
isPublic: isPublic ? true : undefined,
},
],
},
include: { members: true },
});
@@ -27,10 +38,15 @@ export default async function getPermission({
} else if (collectionId) {
const check = await prisma.collection.findFirst({
where: {
AND: {
id: collectionId,
OR: [{ ownerId: userId }, { members: { some: { userId } } }],
},
[isPublic ? "OR" : "AND"]: [
{
id: collectionId,
OR: [{ ownerId: userId }, { members: { some: { userId } } }],
},
{
isPublic: isPublic ? true : undefined,
},
],
},
include: { members: true },
});