feat(web): add public commission request entrypoint

This commit is contained in:
2026-02-12 21:35:34 +01:00
parent dc0a41a5ae
commit 1fddb6d858
12 changed files with 441 additions and 9 deletions

View File

@@ -2,6 +2,7 @@ import {
commissionStatusSchema,
createCommissionInputSchema,
createCustomerInputSchema,
createPublicCommissionRequestInputSchema,
updateCommissionStatusInputSchema,
} from "@cms/content"
@@ -56,6 +57,63 @@ export async function createCommission(input: unknown) {
})
}
export async function createPublicCommissionRequest(input: unknown) {
const payload = createPublicCommissionRequestInputSchema.parse(input)
const normalizedEmail = payload.customerEmail.trim().toLowerCase()
return db.$transaction(async (tx) => {
const existingCustomer = await tx.customer.findFirst({
where: {
email: normalizedEmail,
},
orderBy: {
updatedAt: "desc",
},
})
const customer = existingCustomer
? await tx.customer.update({
where: { id: existingCustomer.id },
data: {
name: payload.customerName,
phone: payload.customerPhone ?? existingCustomer.phone,
instagram: payload.customerInstagram ?? existingCustomer.instagram,
isRecurring: true,
},
})
: await tx.customer.create({
data: {
name: payload.customerName,
email: normalizedEmail,
phone: payload.customerPhone,
instagram: payload.customerInstagram,
isRecurring: false,
},
})
return tx.commission.create({
data: {
title: payload.title,
description: payload.description,
status: "new",
customerId: customer.id,
budgetMin: payload.budgetMin,
budgetMax: payload.budgetMax,
},
include: {
customer: {
select: {
id: true,
name: true,
email: true,
isRecurring: true,
},
},
},
})
})
}
export async function updateCommissionStatus(input: unknown) {
const payload = updateCommissionStatusInputSchema.parse(input)