handle undefined

This commit is contained in:
jlssmt 2024-07-25 22:50:38 +02:00 committed by Julius Schmitt
parent a82c4ef85f
commit 102690fc10

View File

@ -86,6 +86,8 @@ export default async function postLink(
else if (contentType === "image/png") imageExtension = "png"; else if (contentType === "image/png") imageExtension = "png";
} }
if (!link.tags) link.tags = [];
const newLink = await prisma.link.create({ const newLink = await prisma.link.create({
data: { data: {
url: link.url?.trim().replace(/\/+$/, "") || null, url: link.url?.trim().replace(/\/+$/, "") || null,
@ -98,7 +100,7 @@ export default async function postLink(
}, },
}, },
tags: { tags: {
connectOrCreate: link.tags.map((tag) => ({ connectOrCreate: link.tags?.map((tag) => ({
where: { where: {
name_ownerId: { name_ownerId: {
name: tag.name.trim(), name: tag.name.trim(),