mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 20:40:55 +00:00
feat(train-scheduling): notify customer of CAS on direct-to-train load
Direct truck-to-train export cargo skips the warehouse, so the existing carriage acceptance sheet ready notice (fired on warehouse receive) never reached these bookings. Their handover moment is the load itself. Extract notifyCarriageAcceptanceReady into a shared notifications util (was private to WarehouseInventoryService) and call it from BookingJourneyService.loadBooking for EXPORT + DIRECT_TO_TRAIN bookings, right after the GRN gate, before the load transaction proceeds.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { DataSource } from 'typeorm';
|
||||
import { Logger } from '@nestjs/common';
|
||||
|
||||
import { NotificationAudience, NotificationType } from '@edr/types';
|
||||
import { NotificationsService } from './notifications.service';
|
||||
import { NotificationInboxService } from '../notification-inbox/notification-inbox.service';
|
||||
import {
|
||||
companyNotifyEmailExpr,
|
||||
companyNotifyPhoneExpr,
|
||||
@@ -42,3 +45,41 @@ export async function sendCompanyChannels(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell the customer their export carriage acceptance sheet is ready to
|
||||
* download from the portal — the sheet itself is generated on demand by
|
||||
* BookingsService.carriageAcceptanceSheet, never stored, so this is a
|
||||
* "ready" notice + link, not an attachment (the email pipeline carries text
|
||||
* only). Shared by every path that makes a booking's handover final: the
|
||||
* warehouse gate on receive, and direct truck-to-train on load (that cargo
|
||||
* never sees a warehouse, so its handover moment IS the load).
|
||||
*/
|
||||
export async function notifyCarriageAcceptanceReady(
|
||||
dataSource: DataSource,
|
||||
notifications: NotificationsService,
|
||||
inbox: NotificationInboxService,
|
||||
bookingId: string,
|
||||
logger: Logger,
|
||||
): Promise<void> {
|
||||
try {
|
||||
const [b]: Array<{ companyId: string | null; reference: string }> = await dataSource.query(
|
||||
`SELECT company_id AS "companyId", reference FROM freight.bookings WHERE id = $1 AND deleted_at IS NULL`,
|
||||
[bookingId],
|
||||
);
|
||||
if (!b?.companyId) return;
|
||||
const body = `Your carriage acceptance sheet for booking ${b.reference} is ready to download from the portal.`;
|
||||
await inbox.notify({
|
||||
recipients: { companyId: b.companyId },
|
||||
audience: NotificationAudience.PORTAL,
|
||||
type: NotificationType.DOCUMENT_ACTION,
|
||||
title: 'Carriage acceptance sheet ready',
|
||||
body,
|
||||
link: `/bookings/${bookingId}`,
|
||||
data: { bookingId, reference: b.reference },
|
||||
});
|
||||
await sendCompanyChannels(dataSource, notifications, b.companyId, body);
|
||||
} catch (err) {
|
||||
logger.warn(`Carriage acceptance ready notify failed for ${bookingId}: ${(err as Error).message}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user