mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 04:08:11 +00:00
Update seatmap and add cron job for payment status
This commit is contained in:
@@ -51,27 +51,30 @@ export class SeatsService {
|
||||
: 0;
|
||||
const bedCategory = isBedCoach ? this.getBedCategory(coachTypeName, bedsPerRoom) : null;
|
||||
|
||||
const mappedSeats = allSeats.map((s: any) => ({
|
||||
id: s.id,
|
||||
seatNumber: s.seatNumber,
|
||||
label: s.seatNumber,
|
||||
status: effectiveStatuses.get(s.id) ?? s.status,
|
||||
kind: s.kind,
|
||||
row: s.row,
|
||||
col: s.col,
|
||||
isWindow: s.isWindow,
|
||||
isAisle: s.isAisle,
|
||||
// Bed-specific fields
|
||||
...(isBedCoach ? {
|
||||
room_id: `${a.coach.id}-R${s.row}`,
|
||||
category: bedCategory,
|
||||
position: this.colToPosition(s.col),
|
||||
bed_type: this.bedPositionToType(s.bedPosition),
|
||||
bedPosition: s.bedPosition,
|
||||
} : {
|
||||
bedPosition: s.bedPosition,
|
||||
}),
|
||||
}));
|
||||
const mappedSeats = allSeats.map((s: any) => {
|
||||
const resolvedBedPosition = isBedCoach
|
||||
? this.resolveBedPosition(s.col, s.bedPosition)
|
||||
: s.bedPosition;
|
||||
return {
|
||||
id: s.id,
|
||||
seatNumber: s.seatNumber,
|
||||
label: s.seatNumber,
|
||||
status: effectiveStatuses.get(s.id) ?? s.status,
|
||||
kind: s.kind,
|
||||
row: s.row,
|
||||
col: s.col,
|
||||
isWindow: s.isWindow,
|
||||
isAisle: s.isAisle,
|
||||
bedPosition: resolvedBedPosition,
|
||||
// Bed-specific fields (only when coach is a bed coach)
|
||||
...(isBedCoach ? {
|
||||
room_id: `${a.coach.id}-R${s.row}`,
|
||||
category: bedCategory,
|
||||
position: this.colToPosition(s.col, a.coach.arrangement),
|
||||
bed_type: this.bedPositionToType(resolvedBedPosition),
|
||||
} : {}),
|
||||
};
|
||||
});
|
||||
|
||||
const base = {
|
||||
id: a.coach.id,
|
||||
@@ -116,7 +119,7 @@ export class SeatsService {
|
||||
|
||||
private isBedCoach(coachTypeName: string): boolean {
|
||||
const n = coachTypeName.toLowerCase();
|
||||
return n.includes('bed') || n.includes('sleeper') || n.includes('couchette');
|
||||
return n.includes('bed') || n.includes('berth') || n.includes('sleeper') || n.includes('couchette');
|
||||
}
|
||||
|
||||
private getBedCategory(coachTypeName: string, bedsPerRoom?: number): 'ECONOMY_BED' | 'VIP_BED' {
|
||||
@@ -128,9 +131,23 @@ export class SeatsService {
|
||||
return 'ECONOMY_BED';
|
||||
}
|
||||
|
||||
// col format: L1, L2, L3, R1, R2, R3
|
||||
private colToPosition(col: string): 'LEFT' | 'RIGHT' {
|
||||
return col?.startsWith('R') ? 'RIGHT' : 'LEFT';
|
||||
// col format: L1, L2, L3, R1, R2, R3 (new) or A, B, C, D (legacy)
|
||||
// arrangement e.g. "2+2", "3+3", "2+0" → "leftCount+rightCount"
|
||||
private colToPosition(col: string, arrangement?: string): 'LEFT' | 'RIGHT' | null {
|
||||
if (!col) return null;
|
||||
// New named-col format: L1, L2, R1, R2 …
|
||||
if (/^L\d+$/.test(col)) return 'LEFT';
|
||||
if (/^R\d+$/.test(col)) return 'RIGHT';
|
||||
// Legacy single-letter cols (A, B, C, D …): derive from arrangement
|
||||
const colIndex = col.toUpperCase().charCodeAt(0) - 65; // A=0, B=1, C=2 …
|
||||
if (arrangement) {
|
||||
const [leftStr, rightStr] = arrangement.split('+');
|
||||
const rightCount = parseInt(rightStr ?? '0', 10);
|
||||
if (rightCount === 0) return 'LEFT'; // single-side berth coach — all LEFT
|
||||
const leftCount = parseInt(leftStr, 10) || 0;
|
||||
return colIndex < leftCount ? 'LEFT' : 'RIGHT';
|
||||
}
|
||||
return 'LEFT'; // safe default when no arrangement info
|
||||
}
|
||||
|
||||
private bedPositionToType(bedPosition: string | null): 'LOWER' | 'MIDDLE' | 'UPPER' | null {
|
||||
@@ -141,6 +158,22 @@ export class SeatsService {
|
||||
return map[bedPosition.toLowerCase()] ?? null;
|
||||
}
|
||||
|
||||
// Derives bedPosition from col when the seat was created with legacy A/B/C columns
|
||||
// (new coaches use L1/L2/L3/R1/R2/R3 and store bedPosition explicitly).
|
||||
// Col-to-tier mapping: A → lower, B → middle, C → upper, D → upper (4-tier).
|
||||
private resolveBedPosition(col: string, storedBedPosition: string | null): string | null {
|
||||
if (storedBedPosition) return storedBedPosition;
|
||||
const legacyMap: Record<string, string> = { A: 'lower', B: 'middle', C: 'upper', D: 'upper' };
|
||||
// Also handle numeric suffix in L/R cols: L1→lower, L2→middle, L3→upper
|
||||
if (/^[LR]\d+$/.test(col)) {
|
||||
const tier = parseInt(col.slice(1), 10);
|
||||
if (tier === 1) return 'lower';
|
||||
if (tier === 2) return 'middle';
|
||||
return 'upper';
|
||||
}
|
||||
return legacyMap[col?.toUpperCase()] ?? null;
|
||||
}
|
||||
|
||||
async resolveEffectiveStatuses(
|
||||
scheduleId: string,
|
||||
seatIds: string[],
|
||||
|
||||
Reference in New Issue
Block a user