52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
"use server";
|
|
|
|
import { prisma } from "@/lib/prisma";
|
|
import {
|
|
commissionCustomCardSchema,
|
|
type CommissionCustomCardValues,
|
|
} from "@/schemas/commissionCustomCard";
|
|
|
|
export async function updateCommissionCustomCard(
|
|
id: string,
|
|
rawData: CommissionCustomCardValues
|
|
) {
|
|
const data = commissionCustomCardSchema.parse(rawData);
|
|
|
|
const updated = await prisma.commissionCustomCard.update({
|
|
where: { id },
|
|
data: {
|
|
name: data.name,
|
|
description: data.description,
|
|
referenceImageUrl: data.referenceImageUrl ?? null,
|
|
isVisible: data.isVisible ?? true,
|
|
isSpecialOffer: data.isSpecialOffer ?? false,
|
|
options: {
|
|
deleteMany: {},
|
|
create: data.options?.map((opt, index) => ({
|
|
option: { connect: { id: opt.optionId } },
|
|
price: opt.price ?? null,
|
|
pricePercent: opt.pricePercent ?? null,
|
|
priceRange: opt.priceRange ?? null,
|
|
sortIndex: index,
|
|
})),
|
|
},
|
|
extras: {
|
|
deleteMany: {},
|
|
create: data.extras?.map((ext, index) => ({
|
|
extra: { connect: { id: ext.extraId } },
|
|
price: ext.price ?? null,
|
|
pricePercent: ext.pricePercent ?? null,
|
|
priceRange: ext.priceRange ?? null,
|
|
sortIndex: index,
|
|
})),
|
|
},
|
|
},
|
|
include: {
|
|
options: true,
|
|
extras: true,
|
|
},
|
|
});
|
|
|
|
return updated;
|
|
}
|