@@ -1,10 +1,13 @@
|
||||
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
||||
import { prisma } from "./db";
|
||||
import getPermission from "./getPermission";
|
||||
import { UsersAndCollections } from "@prisma/client";
|
||||
import { PostLinkSchemaType } from "../shared/schemaValidation";
|
||||
|
||||
const setLinkCollection = async (link: PostLinkSchemaType, userId: number) => {
|
||||
if (link.collection?.id && typeof link.collection?.id === "number") {
|
||||
const setLinkCollection = async (
|
||||
link: LinkIncludingShortenedCollectionAndTags,
|
||||
userId: number
|
||||
) => {
|
||||
if (link?.collection?.id && typeof link?.collection?.id === "number") {
|
||||
const existingCollection = await prisma.collection.findUnique({
|
||||
where: {
|
||||
id: link.collection.id,
|
||||
@@ -26,7 +29,7 @@ const setLinkCollection = async (link: PostLinkSchemaType, userId: number) => {
|
||||
return null;
|
||||
|
||||
return existingCollection;
|
||||
} else if (link.collection?.name) {
|
||||
} else if (link?.collection?.name) {
|
||||
if (link.collection.name === "Unorganized") {
|
||||
const firstTopLevelUnorganizedCollection =
|
||||
await prisma.collection.findFirst({
|
||||
@@ -45,7 +48,6 @@ const setLinkCollection = async (link: PostLinkSchemaType, userId: number) => {
|
||||
data: {
|
||||
name: link.collection.name.trim(),
|
||||
ownerId: userId,
|
||||
createdById: userId,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -79,7 +81,6 @@ const setLinkCollection = async (link: PostLinkSchemaType, userId: number) => {
|
||||
name: "Unorganized",
|
||||
ownerId: userId,
|
||||
parentId: null,
|
||||
createdById: userId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user