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
@@ -1,5 +1,5 @@
import { prisma } from "@/lib/api/db";
import { Collection, Link, UsersAndCollections } from "@prisma/client";
import { Collection, UsersAndCollections } from "@prisma/client";
import getPermission from "@/lib/api/getPermission";
export default async function getLinkById(userId: number, linkId: number) {
@@ -27,7 +27,7 @@ export default async function getLinkById(userId: number, linkId: number) {
status: 401,
};
else {
const updatedLink = await prisma.link.findUnique({
const link = await prisma.link.findUnique({
where: {
id: linkId,
},
@@ -43,6 +43,6 @@ export default async function getLinkById(userId: number, linkId: number) {
},
});
return { response: updatedLink, status: 200 };
return { response: link, status: 200 };
}
}
@@ -0,0 +1,24 @@
import { prisma } from "@/lib/api/db";
export default async function getLinkById(linkId: number) {
if (!linkId)
return {
response: "Please choose a valid link.",
status: 401,
};
const link = await prisma.link.findFirst({
where: {
id: linkId,
collection: {
isPublic: true,
},
},
include: {
tags: true,
collection: true,
},
});
return { response: link, status: 200 };
}
+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 },
});