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.

This commit is contained in:
paritosh18
2026-01-08 15:18:06 +05:30
parent 82ba980b6f
commit 4953a179a6

View File

@@ -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,