Throttling configuration from the backoffice added

This commit is contained in:
Stephanos A
2026-06-26 12:17:01 +03:00
parent 84a14b7312
commit eefbe6e8ed
8 changed files with 152 additions and 21 deletions

View File

@@ -20,7 +20,7 @@ export class PackagesService {
listActive() {
const now = new Date();
return this.prisma.travelPackage.findMany({
where: { status: 'ACTIVE', validFrom: { lte: now }, validUntil: { gte: now } },
where: { status: 'ACTIVE', validUntil: { gte: now } },
include: {
priceTiers: true,
outboundSchedule: { include: { originStation: true, destinationStation: true } },
@@ -145,6 +145,12 @@ export class PackagesService {
return this.prisma.travelPackage.update({ where: { id }, data: { status: 'ACTIVE' } });
}
async deactivate(id: string) {
const pkg = await this.prisma.travelPackage.findUnique({ where: { id } });
if (!pkg) throw new NotFoundException('Package not found');
return this.prisma.travelPackage.update({ where: { id }, data: { status: 'DRAFT' } });
}
async book(dto: BookPackageDto, passengerId?: string) {
const pkg = await this.prisma.travelPackage.findUnique({
where: { id: dto.packageId },
@@ -152,7 +158,6 @@ export class PackagesService {
});
if (!pkg) throw new NotFoundException('Package not found');
if (pkg.status !== 'ACTIVE') throw new BadRequestException('Package is not available for booking');
if (new Date() > pkg.validUntil) throw new BadRequestException('Package has expired');
const tier = pkg.priceTiers.find((t) => t.id === dto.priceTierId);
if (!tier) throw new NotFoundException('Price tier not found');