From 4953a179a6e17122e76b3aed5b51d4c6df1177b1 Mon Sep 17 00:00:00 2001 From: paritosh18 Date: Thu, 8 Jan 2026 15:18:06 +0530 Subject: [PATCH] Enhance validation logic in HostService for venue and equipment pricing. Implement checks for draft status to allow zero values in draft mode while enforcing positive values on submission. Update query to include unreviewed activities. --- src/modules/host/services/host.service.ts | 45 +++++++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/src/modules/host/services/host.service.ts b/src/modules/host/services/host.service.ts index 559483a..4ddc6ab 100644 --- a/src/modules/host/services/host.service.ts +++ b/src/modules/host/services/host.service.ts @@ -2742,7 +2742,7 @@ export class HostService { } /* -------------------------------- - * 8️⃣ CREATE VENUES WITH MEDIA & PRICES + * 8️⃣ CREATE VENUES WITH MEDIA & PRICES (DRAFT SAFE) * -------------------------------- */ for (const venue of payload.venues ?? []) { const venueRow = await tx.activityVenues.create({ @@ -2774,6 +2774,19 @@ export class HostService { // Create venue prices with taxes for (const price of venue.prices ?? []) { const sellPrice = Number(price.sellPrice); + + // On submit enforce > 0, on draft just skip invalid + if (!isDraft) { + if (!sellPrice || sellPrice <= 0) { + throw new ApiError( + 400, + 'sellPrice must be > 0 for submitted activities', + ); + } + } + + if (!sellPrice || sellPrice <= 0) continue; + const { basePrice, taxDetails } = computeBasePriceAndTaxes( sellPrice, rootTaxes, @@ -2901,7 +2914,21 @@ export class HostService { if (Array.isArray(payload.equipments) && payload.equipments.length) { for (const eq of payload.equipments) { - const totalPrice = toNumber(eq.equipmentTotalPrice) ?? 0; + const isChargeable = toBool(eq.isEquipmentChargeable); + const totalPrice = isChargeable + ? toNumber(eq.equipmentTotalPrice) ?? 0 + : 0; + + // On submit enforce > 0, on draft just skip invalid/zero + if (!isDraft && isChargeable && totalPrice <= 0) { + throw new ApiError( + 400, + 'equipmentTotalPrice must be > 0 when equipment is chargeable', + ); + } + + if (!isChargeable || totalPrice <= 0) continue; + const { basePrice, taxDetails } = computeBasePriceAndTaxes( totalPrice, rootTaxes, @@ -2911,7 +2938,7 @@ export class HostService { data: { activityXid, equipmentName: eq.equipmentName, - isEquipmentChargeable: toBool(eq.isEquipmentChargeable), + isEquipmentChargeable: isChargeable, equipmentBasePrice: basePrice, equipmentTotalPrice: totalPrice, }, @@ -3020,6 +3047,16 @@ export class HostService { for (const detail of transport.pickupDetails) { const totalPrice = toNumber(detail.transportTotalPrice) ?? 0; + // On submit enforce > 0, on draft just skip + if (!isDraft && totalPrice <= 0) { + throw new ApiError( + 400, + 'transportTotalPrice must be > 0 when chargeable', + ); + } + + if (totalPrice <= 0) continue; + const { basePrice, taxDetails } = computeBasePriceAndTaxes( totalPrice, rootTaxes, @@ -3345,7 +3382,7 @@ export class HostService { }, }, ActivityPQQSuggestions: { - where: { isActive: true }, + where: { isActive: true , isReviewed :false }, select: { id: true, title: true,