mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import { Injectable, NotFoundException, ConflictException } from '@nestjs/common';
|
|
import { PrismaService } from '../../common/prisma.service';
|
|
|
|
@Injectable()
|
|
export class SeatClassesService {
|
|
constructor(private prisma: PrismaService) {}
|
|
|
|
listSeatClasses() {
|
|
return this.prisma.seatClass.findMany({
|
|
where: { isActive: true },
|
|
orderBy: { createdAt: 'asc' },
|
|
});
|
|
}
|
|
|
|
async getSeatClass(id: string) {
|
|
const sc = await this.prisma.seatClass.findUnique({ where: { id } });
|
|
if (!sc) throw new NotFoundException('SeatClass not found');
|
|
if (!sc.isActive) throw new NotFoundException('SeatClass is not active');
|
|
return sc;
|
|
}
|
|
|
|
async createSeatClass(dto: any) {
|
|
try {
|
|
return await this.prisma.seatClass.create({ data: dto });
|
|
} catch (e: any) {
|
|
if (e.code === 'P2002') throw new ConflictException(`Seat class "${dto.name}" already exists`);
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
async updateSeatClass(id: string, dto: any) {
|
|
const sc = await this.prisma.seatClass.findUnique({ where: { id } });
|
|
if (!sc) throw new NotFoundException('SeatClass not found');
|
|
return this.prisma.seatClass.update({ where: { id }, data: dto });
|
|
}
|
|
|
|
async deleteSeatClass(id: string) {
|
|
const sc = await this.prisma.seatClass.findUnique({ where: { id } });
|
|
if (!sc) throw new NotFoundException('SeatClass not found');
|
|
return this.prisma.seatClass.delete({ where: { id } });
|
|
}
|
|
}
|