Add request single page

This commit is contained in:
2026-01-01 11:52:24 +01:00
parent 42f23dddcf
commit 2fcf19c0df
13 changed files with 1007 additions and 83 deletions

View File

@ -0,0 +1,53 @@
"use server";
import { prisma } from "@/lib/prisma";
import { calculatePriceRange, PriceSource } from "@/utils/commissionPricing";
export async function getCommissionRequestById(id: string) {
const req = await prisma.commissionRequest.findUnique({
where: { id },
include: {
type: { select: { id: true, name: true } },
option: { select: { id: true, name: true } },
extras: { select: { id: true, name: true } },
files: {
orderBy: { createdAt: "asc" },
select: {
id: true,
createdAt: true,
originalFile: true,
fileType: true,
fileSize: true,
},
},
},
});
if (!req) return null;
const baseSource: PriceSource | undefined =
req.typeId && req.optionId
? await prisma.commissionTypeOption.findUnique({
where: { typeId_optionId: { typeId: req.typeId, optionId: req.optionId } },
select: { price: true, pricePercent: true, priceRange: true },
}) ?? undefined
: undefined;
const extrasSources: PriceSource[] =
req.typeId && req.extras.length
? await prisma.commissionTypeExtra.findMany({
where: {
typeId: req.typeId,
extraId: { in: req.extras.map((e) => e.id) },
},
select: { price: true, pricePercent: true, priceRange: true },
})
: [];
const [min, max] = calculatePriceRange(baseSource, extrasSources);
return {
...req,
priceEstimate: { min, max },
};
}

View File

@ -0,0 +1,31 @@
"use server";
import { prisma } from "@/lib/prisma";
import { commissionStatusSchema } from "@/schemas/commissions/tableSchema";
import { z } from "zod/v4";
const updateSchema = z.object({
id: z.string().min(1),
status: commissionStatusSchema,
customerName: z.string().min(1).max(200),
customerEmail: z.string().email().max(320),
customerSocials: z.string().max(2000).optional().nullable(),
message: z.string().min(1).max(20_000),
});
export async function updateCommissionRequest(input: z.infer<typeof updateSchema>) {
const data = updateSchema.parse(input);
await prisma.commissionRequest.update({
where: { id: data.id },
data: {
status: data.status,
customerName: data.customerName,
customerEmail: data.customerEmail,
customerSocials: data.customerSocials ?? null,
message: data.message,
},
});
return { ok: true };
}