mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 21:08:12 +00:00
feat: enhance booking operations to support freight forwarder variants and improve consolidation handling
This commit is contained in:
@@ -447,18 +447,50 @@ private async seedWeightLimits(wlRepo: any, ctRepo: any): Promise<void> {
|
||||
{ appliesTo: "OTHER", trigger: "CONSOLIDATION", rateType: "LASHING", rateValue: 50, rateUnit: "PER_CONTAINER" },
|
||||
];
|
||||
|
||||
const entities = rateData.map((d) =>
|
||||
rRepo.create({
|
||||
// Idempotent: insert each canonical rate only if no row with the same
|
||||
// signature already exists. Re-running the seeder must NOT accumulate
|
||||
// duplicate rows — duplicated surcharge rates would otherwise repeat on
|
||||
// every booking's price breakdown.
|
||||
const signature = (r: {
|
||||
rateType: string;
|
||||
rateUnit: string;
|
||||
rateValue: number;
|
||||
currency: string;
|
||||
containerTypeId?: string | null;
|
||||
cargoTypeId?: string | null;
|
||||
}) =>
|
||||
[
|
||||
r.rateType,
|
||||
r.rateUnit,
|
||||
Number(r.rateValue),
|
||||
r.currency,
|
||||
r.containerTypeId ?? "",
|
||||
r.cargoTypeId ?? "",
|
||||
].join("|");
|
||||
|
||||
const existing: Rate[] = await rRepo.find();
|
||||
const existingBySignature = new Set(existing.map((r) => signature(r)));
|
||||
|
||||
const toCreate = rateData
|
||||
.map((d) => ({
|
||||
currency: "USD",
|
||||
...d,
|
||||
status: "LIVE",
|
||||
status: "LIVE" as const,
|
||||
proposedByStaffId: STAFF_USER_ID,
|
||||
approvedByCeoId: CEO_USER_ID,
|
||||
approvedAt: now,
|
||||
effectiveFrom,
|
||||
}),
|
||||
);
|
||||
return rRepo.save(entities);
|
||||
}))
|
||||
.filter((d) => !existingBySignature.has(signature(d)));
|
||||
|
||||
if (toCreate.length === 0) {
|
||||
this.logger.log("Rates already seeded — skipping (idempotent)");
|
||||
return existing;
|
||||
}
|
||||
|
||||
const created = await rRepo.save(toCreate.map((d) => rRepo.create(d)));
|
||||
this.logger.log(`Seeded ${created.length} new rate(s)`);
|
||||
return [...existing, ...created];
|
||||
}
|
||||
|
||||
private async seedDraftBookings(
|
||||
|
||||
Reference in New Issue
Block a user