mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 00:52:50 +00:00
changes
This commit is contained in:
@@ -20,6 +20,7 @@ import { DataSource, EntityManager, In, IsNull, Not } from 'typeorm';
|
|||||||
import { BookingsRepository } from '../bookings/bookings.repository';
|
import { BookingsRepository } from '../bookings/bookings.repository';
|
||||||
import { Booking } from '../bookings/entities/booking.entity';
|
import { Booking } from '../bookings/entities/booking.entity';
|
||||||
import { BookingContainer } from '../bookings/entities/booking-container.entity';
|
import { BookingContainer } from '../bookings/entities/booking-container.entity';
|
||||||
|
import { ClearanceMilestone } from '../contracts/entities/clearance-milestone.entity';
|
||||||
import { Container } from '../container-management/entities/container.entity';
|
import { Container } from '../container-management/entities/container.entity';
|
||||||
import { Locomotive } from '../locomotives/entities/locomotive.entity';
|
import { Locomotive } from '../locomotives/entities/locomotive.entity';
|
||||||
import { LocomotivesRepository } from '../locomotives/locomotives.repository';
|
import { LocomotivesRepository } from '../locomotives/locomotives.repository';
|
||||||
@@ -1168,12 +1169,47 @@ export class TrainSchedulingService {
|
|||||||
notes: dto.notes ?? operation.notes ?? null,
|
notes: dto.notes ?? operation.notes ?? null,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await this.completeGatepassMilestoneForSchedule(scheduleId, securedAt);
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`[NOTIFY] Gate pass secured for train ${schedule.trainNumber ?? schedule.id}; Djibouti Port entry is allowed.`,
|
`[NOTIFY] Gate pass secured for train ${schedule.trainNumber ?? schedule.id}; Djibouti Port entry is allowed.`,
|
||||||
);
|
);
|
||||||
return this.getImportDjiboutiOperation(schedule.id);
|
return this.getImportDjiboutiOperation(schedule.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bridge write: also flips the legacy clearance-side GATEPASS_GRANTED
|
||||||
|
* milestone for every customs booking on this schedule, so contract/booking
|
||||||
|
* clearance views still reading that milestone (older deployed builds) see
|
||||||
|
* the gate pass as done. Drop once every clearance-api deployment reads
|
||||||
|
* ImportDjiboutiOperation.gatepassGrantedAt directly.
|
||||||
|
*/
|
||||||
|
private async completeGatepassMilestoneForSchedule(
|
||||||
|
scheduleId: string,
|
||||||
|
securedAt: Date,
|
||||||
|
): Promise<void> {
|
||||||
|
const bookings = await this.dataSource.getRepository(Booking).find({
|
||||||
|
where: { trainScheduleId: scheduleId, customsClearingEnabled: true },
|
||||||
|
});
|
||||||
|
if (bookings.length === 0) return;
|
||||||
|
|
||||||
|
const milestoneRepo = this.dataSource.getRepository(ClearanceMilestone);
|
||||||
|
const rows = await milestoneRepo.find({
|
||||||
|
where: {
|
||||||
|
bookingId: In(bookings.map((b) => b.id)),
|
||||||
|
milestoneCode: 'GATEPASS_GRANTED',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const row of rows) {
|
||||||
|
if (row.status === 'COMPLETED') continue;
|
||||||
|
row.status = 'COMPLETED';
|
||||||
|
row.triggeredAt = securedAt;
|
||||||
|
row.metadata = { ...(row.metadata ?? {}), gatepassAt: securedAt.toISOString() };
|
||||||
|
await milestoneRepo.save(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async markImportReadyForLoading(scheduleId: string, dto: ImportDjiboutiActionDto = {}) {
|
async markImportReadyForLoading(scheduleId: string, dto: ImportDjiboutiActionDto = {}) {
|
||||||
const schedule = await this.getImportDjiboutiSchedule(scheduleId);
|
const schedule = await this.getImportDjiboutiSchedule(scheduleId);
|
||||||
const operation = await this.getOrCreateImportDjiboutiOperation(scheduleId);
|
const operation = await this.getOrCreateImportDjiboutiOperation(scheduleId);
|
||||||
|
|||||||
Reference in New Issue
Block a user