Refactor images

This commit is contained in:
2025-07-20 12:49:47 +02:00
parent f3c648e854
commit 312b2c2f94
43 changed files with 2486 additions and 177 deletions

View File

@ -0,0 +1,70 @@
"use server"
import prisma from "@/lib/prisma";
import { imageSchema } from "@/schemas/portfolio/imageSchema";
import { z } from "zod/v4";
export async function updateImage(
values: z.infer<typeof imageSchema>,
id: string
) {
const validated = imageSchema.safeParse(values);
if (!validated.success) {
throw new Error("Invalid image data");
}
const {
fileKey,
originalFile,
nsfw,
published,
altText,
description,
fileType,
name,
fileSize,
creationDate,
tagIds,
categoryIds
} = validated.data;
const updatedImage = await prisma.portfolioImage.update({
where: { id: id },
data: {
fileKey,
originalFile,
nsfw,
published,
altText,
description,
fileType,
name,
fileSize,
creationDate,
}
});
if (tagIds) {
await prisma.portfolioImage.update({
where: { id: id },
data: {
tags: {
set: tagIds.map(id => ({ id }))
}
}
});
}
if (categoryIds) {
await prisma.portfolioImage.update({
where: { id: id },
data: {
categories: {
set: categoryIds.map(id => ({ id }))
}
}
});
}
return updatedImage
}