mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 01:48:12 +00:00
Merge branch 'alpha' of github.com:Tria-plc/edr-platform into alpha
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common';
|
||||
import { Body, Controller, Delete, Get, Param, Patch, Post, Query } from '@nestjs/common';
|
||||
import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam, ApiResponse, ApiBody } from '@nestjs/swagger';
|
||||
import { IsPublic } from '@tria-plc/api-common/modules/auth/decorators/public.decorator';
|
||||
import { SeatClassesService } from './seat-classes.service';
|
||||
@@ -49,5 +49,7 @@ export class SeatClassesController {
|
||||
@ApiParam({ name: 'id', description: 'Seat class UUID' })
|
||||
@ApiResponse({ status: 200, description: 'Seat class deleted' })
|
||||
@ApiResponse({ status: 404, description: 'Seat class not found' })
|
||||
deleteSeatClass(@Param('id') id: string) { return this.service.deleteSeatClass(id); }
|
||||
deleteSeatClass(@Param('id') id: string, @Query('cascade') cascade?: string) {
|
||||
return this.service.deleteSeatClass(id, cascade === 'true');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ export class SeatClassesService {
|
||||
}
|
||||
}
|
||||
|
||||
async deleteSeatClass(id: string) {
|
||||
async deleteSeatClass(id: string, cascade = false) {
|
||||
const sc = await this.prisma.seatClass.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
@@ -59,11 +59,17 @@ export class SeatClassesService {
|
||||
(sc as any)._count.routeFareRules +
|
||||
(sc as any)._count.segmentFares;
|
||||
|
||||
if (totalFareRules > 0)
|
||||
if (totalFareRules > 0 && !cascade)
|
||||
throw new DeleteOperationException('Seat Class', sc.name, [
|
||||
{ entityName: 'fare rule', count: totalFareRules, action: 'delete' },
|
||||
]);
|
||||
|
||||
if (cascade) {
|
||||
await this.prisma.fareRule.deleteMany({ where: { seatClassId: id } });
|
||||
await this.prisma.routeFareRule.deleteMany({ where: { seatClassId: id } });
|
||||
await this.prisma.segmentFareRule.deleteMany({ where: { seatClassId: id } });
|
||||
}
|
||||
|
||||
return this.prisma.seatClass.delete({ where: { id } });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user