Tour package booking, app release, new endpoints, more updates and fixes

This commit is contained in:
Stephanos A
2026-07-05 00:28:06 +03:00
parent 868639084c
commit 595be6e123
68 changed files with 2773 additions and 787 deletions

View File

@@ -3,6 +3,7 @@ import { REQUEST } from '@nestjs/core';
import { PrismaService } from '../../common/prisma.service';
import { AuditService } from '../../common/audit.service';
import { CreateStationDto } from './stations.dto';
import { DeleteOperationException } from '../../common/exceptions/delete-operation.exception';
interface StationFilters {
search?: string;
@@ -96,7 +97,35 @@ export class StationsService {
}
async remove(id: string) {
const station = await this.findOne(id);
const station = await this.prisma.station.findUnique({
where: { id },
include: {
_count: { select: { stopTimes: true } },
originSchedules: { take: 1, select: { id: true } },
destinationSchedules: { take: 1, select: { id: true } },
},
});
if (!station) throw new NotFoundException('Station not found');
const [routeStopCount, originCount, destCount, stopTimeCount] = await Promise.all([
this.prisma.routeStop.count({ where: { stationId: id } }),
this.prisma.trainSchedule.count({ where: { originStationId: id } }),
this.prisma.trainSchedule.count({ where: { destinationStationId: id } }),
(station as any)._count.stopTimes as number,
]);
const constraints = [];
if (routeStopCount > 0)
constraints.push({ entityName: 'route', count: routeStopCount, action: 'delete' as const });
const scheduleCount = originCount + destCount;
if (scheduleCount > 0)
constraints.push({ entityName: 'schedule', count: scheduleCount, action: 'delete' as const });
if (stopTimeCount > 0)
constraints.push({ entityName: 'stop time', count: stopTimeCount, action: 'delete' as const });
if (constraints.length > 0)
throw new DeleteOperationException('Station', `${station.name} (${station.code})`, constraints);
const deleted = await this.prisma.station.delete({ where: { id } });
await this.auditService.log({