critical bug fixed + improvements

This commit is contained in:
Daniel
2023-06-25 01:24:35 +03:30
parent fa71d9ba86
commit 0ddd9079bf
13 changed files with 167 additions and 108 deletions
+9 -5
View File
@@ -2,7 +2,7 @@ import { prisma } from "@/lib/api/db";
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
import getTitle from "../../getTitle";
import archive from "../../archive";
import { Link, UsersAndCollections } from "@prisma/client";
import { Collection, Link, UsersAndCollections } from "@prisma/client";
import getPermission from "@/lib/api/getPermission";
import { existsSync, mkdirSync } from "fs";
@@ -13,16 +13,20 @@ export default async function postLink(
link.collection.name = link.collection.name.trim();
if (!link.name) {
return { response: "Please enter a valid name for the link.", status: 401 };
return { response: "Please enter a valid name for the link.", status: 400 };
} else if (!link.collection.name) {
return { response: "Please enter a valid collection name.", status: 401 };
return { response: "Please enter a valid collection.", status: 400 };
}
if (link.collection.id) {
const collectionIsAccessible = await getPermission(
const collectionIsAccessible = (await getPermission(
userId,
link.collection.id
);
)) as
| (Collection & {
members: UsersAndCollections[];
})
| null;
const memberHasAccess = collectionIsAccessible?.members.some(
(e: UsersAndCollections) => e.userId === userId && e.canCreate