Production checklists, issue fixes

This commit is contained in:
Stephanos A
2026-07-01 15:04:38 +03:00
parent 0015f645cf
commit 103117d88b
20 changed files with 100 additions and 200 deletions

View File

@@ -100,10 +100,15 @@ export class SchedulesService {
const arr = parseEthiopianTime(dto.arrivalAt);
if (arr <= dep) throw new BadRequestException('arrivalAt must be after departureAt');
const route = await this.prisma.route.findUnique({
where: { id: dto.routeId },
include: { stops: { orderBy: { sequence: 'asc' } } },
});
const [train, route] = await Promise.all([
this.prisma.train.findUnique({ where: { id: dto.trainId } }),
this.prisma.route.findUnique({
where: { id: dto.routeId },
include: { stops: { orderBy: { sequence: 'asc' } } },
}),
]);
if (!train) throw new NotFoundException('Train not found');
if (!train.isActive) throw new BadRequestException('Train is not active');
if (!route) throw new NotFoundException('Route not found');
if (!route.active) throw new BadRequestException('Route is not active');
if (route.stops.length < 2) throw new BadRequestException('Route must have at least 2 stops');
@@ -247,10 +252,15 @@ export class SchedulesService {
const arr = parseEthiopianTime(dto.arrivalAt);
if (arr <= dep) throw new BadRequestException('arrivalAt must be after departureAt');
const route = await this.prisma.route.findUnique({
where: { id: dto.routeId },
include: { stops: { orderBy: { sequence: 'asc' } } },
});
const [train, route] = await Promise.all([
this.prisma.train.findUnique({ where: { id: dto.trainId } }),
this.prisma.route.findUnique({
where: { id: dto.routeId },
include: { stops: { orderBy: { sequence: 'asc' } } },
}),
]);
if (!train) throw new NotFoundException('Train not found');
if (!train.isActive) throw new BadRequestException('Train is not active');
if (!route) throw new NotFoundException('Route not found');
if (!route.active) throw new BadRequestException('Route is not active');
if (route.stops.length < 2) throw new BadRequestException('Route must have at least 2 stops');
@@ -540,6 +550,8 @@ export class SchedulesService {
const coachIds = coaches.map(c => c.coachId);
const existingCoaches = await this.prisma.coach.findMany({ where: { id: { in: coachIds } } });
if (existingCoaches.length !== coachIds.length) throw new NotFoundException('One or more coaches not found');
const inactiveCoach = existingCoaches.find(c => c.status !== 'ACTIVE');
if (inactiveCoach) throw new BadRequestException(`Coach ${inactiveCoach.number} is not active`);
await this.prisma.coachAssignment.deleteMany({ where: { scheduleId } });