Add tags to commssion types and custom types. Add button for example images to cards

This commit is contained in:
2026-02-02 17:00:03 +01:00
parent 93a327c634
commit c915df904d
25 changed files with 617 additions and 367 deletions

View File

@ -25,6 +25,9 @@ export async function createCommissionCustomCard(
referenceImageUrl: data.referenceImageUrl ?? null,
isVisible: data.isVisible ?? true,
isSpecialOffer: data.isSpecialOffer ?? false,
tags: data.tagIds?.length
? { connect: data.tagIds.map((id) => ({ id })) }
: undefined,
options: {
create:
data.options?.map((opt, index) => ({

View File

@ -20,6 +20,12 @@ export async function updateCommissionCustomCard(
referenceImageUrl: data.referenceImageUrl ?? null,
isVisible: data.isVisible ?? true,
isSpecialOffer: data.isSpecialOffer ?? false,
tags: data.tagIds
? {
set: [],
connect: data.tagIds.map((id) => ({ id })),
}
: undefined,
options: {
deleteMany: {},
create: data.options?.map((opt, index) => ({

View File

@ -1,7 +1,7 @@
"use server"
"use server";
import { prisma } from "@/lib/prisma"
import { commissionTypeSchema } from "@/schemas/commissionType"
import { prisma } from "@/lib/prisma";
import { commissionTypeSchema } from "@/schemas/commissionType";
export async function createCommissionOption(data: { name: string }) {
return await prisma.commissionOption.create({
@ -9,7 +9,7 @@ export async function createCommissionOption(data: { name: string }) {
name: data.name,
description: "",
},
})
});
}
export async function createCommissionExtra(data: { name: string }) {
@ -18,64 +18,70 @@ export async function createCommissionExtra(data: { name: string }) {
name: data.name,
description: "",
},
})
});
}
export async function createCommissionCustomInput(data: {
name: string
fieldId: string
name: string;
fieldId: string;
}) {
return await prisma.commissionCustomInput.create({
data: {
name: data.name,
fieldId: data.fieldId,
},
})
});
}
export async function createCommissionType(formData: commissionTypeSchema) {
const parsed = commissionTypeSchema.safeParse(formData)
const parsed = commissionTypeSchema.safeParse(formData);
if (!parsed.success) {
console.error("Validation failed", parsed.error)
throw new Error("Invalid input")
console.error("Validation failed", parsed.error);
throw new Error("Invalid input");
}
const data = parsed.data
const data = parsed.data;
const created = await prisma.commissionType.create({
data: {
name: data.name,
description: data.description,
tags: data.tagIds?.length
? { connect: data.tagIds.map((id) => ({ id })) }
: undefined,
options: {
create: data.options?.map((opt, index) => ({
option: { connect: { id: opt.optionId } },
price: opt.price,
pricePercent: opt.pricePercent,
priceRange: opt.priceRange,
sortIndex: index,
})) || [],
create:
data.options?.map((opt, index) => ({
option: { connect: { id: opt.optionId } },
price: opt.price,
pricePercent: opt.pricePercent,
priceRange: opt.priceRange,
sortIndex: index,
})) || [],
},
extras: {
create: data.extras?.map((ext, index) => ({
extra: { connect: { id: ext.extraId } },
price: ext.price,
pricePercent: ext.pricePercent,
priceRange: ext.priceRange,
sortIndex: index,
})) || [],
create:
data.extras?.map((ext, index) => ({
extra: { connect: { id: ext.extraId } },
price: ext.price,
pricePercent: ext.pricePercent,
priceRange: ext.priceRange,
sortIndex: index,
})) || [],
},
customInputs: {
create: data.customInputs?.map((c, index) => ({
customInput: { connect: { id: c.customInputId } },
label: c.label,
inputType: c.inputType,
required: c.required,
sortIndex: index,
})) || [],
create:
data.customInputs?.map((c, index) => ({
customInput: { connect: { id: c.customInputId } },
label: c.label,
inputType: c.inputType,
required: c.required,
sortIndex: index,
})) || [],
},
},
})
});
return created
}
return created;
}

View File

@ -1,20 +1,26 @@
"use server"
"use server";
import { prisma } from "@/lib/prisma"
import { commissionTypeSchema } from "@/schemas/commissionType"
import * as z from "zod/v4"
import { prisma } from "@/lib/prisma";
import { commissionTypeSchema } from "@/schemas/commissionType";
import type * as z from "zod/v4";
export async function updateCommissionType(
id: string,
rawData: z.infer<typeof commissionTypeSchema>
rawData: z.infer<typeof commissionTypeSchema>,
) {
const data = commissionTypeSchema.parse(rawData)
const data = commissionTypeSchema.parse(rawData);
const updated = await prisma.commissionType.update({
where: { id },
data: {
name: data.name,
description: data.description,
tags: data.tagIds
? {
set: [],
connect: data.tagIds.map((id) => ({ id })),
}
: undefined,
options: {
deleteMany: {},
create: data.options?.map((opt, index) => ({
@ -37,13 +43,14 @@ export async function updateCommissionType(
},
customInputs: {
deleteMany: {},
create: data.customInputs?.map((c, index) => ({
customInput: { connect: { id: c.customInputId } },
label: c.label,
inputType: c.inputType,
required: c.required,
sortIndex: index,
})) || [],
create:
data.customInputs?.map((c, index) => ({
customInput: { connect: { id: c.customInputId } },
label: c.label,
inputType: c.inputType,
required: c.required,
sortIndex: index,
})) || [],
},
},
include: {
@ -51,7 +58,7 @@ export async function updateCommissionType(
extras: true,
customInputs: true,
},
})
});
return updated
return updated;
}

View File

@ -1,5 +0,0 @@
"use server";
export async function migrateArtTags() {
throw new Error("Migration disabled: ArtTag models removed.");
}

View File

@ -1,75 +0,0 @@
"use server";
import { prisma } from "@/lib/prisma";
import { revalidatePath } from "next/cache";
type JoinMigrationResult = {
ok: boolean;
copied: number;
oldExists: boolean;
newExists: boolean;
droppedOld: boolean;
message?: string;
};
export async function migrateArtworkTagJoin(
opts: { dropOld?: boolean } = {},
): Promise<JoinMigrationResult> {
const dropOld = Boolean(opts.dropOld);
const [oldRow, newRow] = await Promise.all([
prisma.$queryRaw<{ name: string | null }[]>`
select to_regclass('_ArtworkTagsV2')::text as name;
`,
prisma.$queryRaw<{ name: string | null }[]>`
select to_regclass('_ArtworkTags')::text as name;
`,
]);
const oldExists = Boolean(oldRow?.[0]?.name);
const newExists = Boolean(newRow?.[0]?.name);
if (!newExists) {
return {
ok: false,
copied: 0,
oldExists,
newExists,
droppedOld: false,
message: "New join table _ArtworkTags does not exist. Run the migration first.",
};
}
if (!oldExists) {
return {
ok: true,
copied: 0,
oldExists,
newExists,
droppedOld: false,
message: "Old join table _ArtworkTagsV2 not found. Nothing to copy.",
};
}
const copied = await prisma.$executeRawUnsafe(`
INSERT INTO "_ArtworkTags" ("A","B")
SELECT "A","B" FROM "_ArtworkTagsV2"
ON CONFLICT ("A","B") DO NOTHING;
`);
let droppedOld = false;
if (dropOld) {
await prisma.$executeRawUnsafe(`DROP TABLE "_ArtworkTagsV2";`);
droppedOld = true;
}
revalidatePath("/tags");
return {
ok: true,
copied: Number(copied ?? 0),
oldExists,
newExists,
droppedOld,
};
}