as per requierment
This commit is contained in:
@@ -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
|
||||
* -------------------------------- */
|
||||
|
||||
Reference in New Issue
Block a user