From b4db2a3bc2d638bfddc56fb887f817aebf065ac0 Mon Sep 17 00:00:00 2001 From: paritosh18 Date: Fri, 9 Jan 2026 19:11:46 +0530 Subject: [PATCH] as per requierment --- src/modules/host/services/host.service.ts | 35 +++++++++-------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/modules/host/services/host.service.ts b/src/modules/host/services/host.service.ts index d796dc8..4f480f0 100644 --- a/src/modules/host/services/host.service.ts +++ b/src/modules/host/services/host.service.ts @@ -2523,16 +2523,6 @@ export class HostService { 'cancellationAllowedBeforeMins must be a positive number (in minutes)', ); } - - if ( - durationMins > 0 && - payload.cancellationAllowedBeforeMins >= durationMins - ) { - throw new ApiError( - 400, - 'cancellationAllowedBeforeMins must be less than activity duration', - ); - } } } else { delete payload.cancellationAllowedBeforeMins; @@ -3126,27 +3116,26 @@ export class HostService { if (Array.isArray(payload.pickupDetails)) { for (const detail of payload.pickupDetails) { const isChargeable = pickUpDropIsChargeable; + + // 🔒 HARD RULE: NOT chargeable → ALWAYS 0 const totalPrice = isChargeable ? toNumber(detail.transportTotalPrice) ?? 0 : 0; - - // On submit enforce > 0 only when chargeable, on draft just skip + + // ❌ Validate ONLY when chargeable + submit if (!isDraft && isChargeable && totalPrice <= 0) { throw new ApiError( 400, - 'transportTotalPrice must be > 0 when chargeable', + 'transportTotalPrice must be > 0 when pickup/drop is chargeable', ); } - - // If chargeable and invalid/zero, skip creating the price row - if (isChargeable && totalPrice <= 0) continue; - + const { basePrice, taxDetails } = isChargeable && totalPrice > 0 ? computeBasePriceAndTaxes(totalPrice, rootTaxes) : { basePrice: 0, taxDetails: [] }; - - /* CREATE PICKUP DETAILS INDEPENDENTLY */ + + // ✅ ALWAYS CREATE PICKUP DETAIL const pickupDetail = await tx.activityPickUpDetails.create({ data: { activitiesXid: activityXid, @@ -3154,12 +3143,14 @@ export class HostService { locationLat: toNumber(detail.locationLat), locationLong: toNumber(detail.locationLong), locationAddress: detail.locationAddress ?? null, + + // ✅ Guaranteed consistency transportBasePrice: basePrice, transportTotalPrice: totalPrice, }, }); - - /* CREATE TAXES FOR PICKUP DETAILS */ + + // 💰 Taxes ONLY when chargeable if (isChargeable && taxDetails.length) { await tx.activityPickUpTransportTaxes.createMany({ data: taxDetails.map((t) => ({ @@ -3172,7 +3163,7 @@ export class HostService { } } } - + /* -------------------------------- * 1️⃣2️⃣ CLEAN & CREATE NAVIGATION MODES WITH TAXES * -------------------------------- */