urls are now editable
This commit is contained in:
@@ -2,7 +2,8 @@ import { prisma } from "@/lib/api/db";
|
||||
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
||||
import { UsersAndCollections } from "@prisma/client";
|
||||
import getPermission from "@/lib/api/getPermission";
|
||||
import { moveFiles } from "@/lib/api/manageLinkFiles";
|
||||
import { moveFiles, removeFiles } from "@/lib/api/manageLinkFiles";
|
||||
import isValidUrl from "@/lib/shared/isValidUrl";
|
||||
|
||||
export default async function updateLinkById(
|
||||
userId: number,
|
||||
@@ -89,16 +90,32 @@ export default async function updateLinkById(
|
||||
status: 401,
|
||||
};
|
||||
else {
|
||||
const oldLink = await prisma.link.findUnique({
|
||||
where: {
|
||||
id: linkId,
|
||||
},
|
||||
});
|
||||
|
||||
if (oldLink && oldLink?.url !== data.url) {
|
||||
await removeFiles(oldLink.id, oldLink.collectionId);
|
||||
}
|
||||
|
||||
const updatedLink = await prisma.link.update({
|
||||
where: {
|
||||
id: linkId,
|
||||
},
|
||||
data: {
|
||||
name: data.name,
|
||||
url: data.url,
|
||||
description: data.description,
|
||||
icon: data.icon,
|
||||
iconWeight: data.iconWeight,
|
||||
color: data.color,
|
||||
image: oldLink?.url !== data.url ? null : undefined,
|
||||
pdf: oldLink?.url !== data.url ? null : undefined,
|
||||
readable: oldLink?.url !== data.url ? null : undefined,
|
||||
monolith: oldLink?.url !== data.url ? null : undefined,
|
||||
preview: oldLink?.url !== data.url ? null : undefined,
|
||||
collection: {
|
||||
connect: {
|
||||
id: data.collection.id,
|
||||
|
||||
Reference in New Issue
Block a user