mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 07:38:10 +00:00
Booking currency updates, audit logging updates
This commit is contained in:
@@ -4,9 +4,10 @@ import { PackagesController } from './packages.controller';
|
||||
import { PackagesService } from './packages.service';
|
||||
import { CurrencyModule } from '../currency/currency.module';
|
||||
import { BookingsModule } from '../bookings/bookings.module';
|
||||
import { AuditModule } from '../../common/audit.module';
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule, CurrencyModule, BookingsModule],
|
||||
imports: [PrismaModule, CurrencyModule, BookingsModule, AuditModule],
|
||||
controllers: [PackagesController],
|
||||
providers: [PackagesService],
|
||||
exports: [PackagesService],
|
||||
|
||||
@@ -5,6 +5,7 @@ import { CreatePackageDto, BookPackageDto, UpdatePriceTierDto, CreatePriceTierDt
|
||||
import { Currency } from '@prisma/client';
|
||||
import { BookingsService } from '../bookings/bookings.service';
|
||||
import { GuestBookingService } from '../bookings/guest-booking.service';
|
||||
import { AuditService } from '../../common/audit.service';
|
||||
|
||||
/** Package-specific fare rules */
|
||||
const PKG_MAX_ADULTS = 5;
|
||||
@@ -49,6 +50,7 @@ export class PackagesService {
|
||||
private readonly currencyService: CurrencyService,
|
||||
private readonly bookingsService: BookingsService,
|
||||
private readonly guestBookingService: GuestBookingService,
|
||||
private readonly auditService: AuditService,
|
||||
) {}
|
||||
|
||||
async getBookingContext(packageId: string, tierId: string, adultCount: number, childCount = 0) {
|
||||
@@ -254,8 +256,8 @@ export class PackagesService {
|
||||
};
|
||||
}
|
||||
|
||||
create(dto: CreatePackageDto) {
|
||||
return this.prisma.travelPackage.create({
|
||||
async create(dto: CreatePackageDto) {
|
||||
const pkg = await this.prisma.travelPackage.create({
|
||||
data: {
|
||||
code: dto.code,
|
||||
name: dto.name,
|
||||
@@ -279,12 +281,14 @@ export class PackagesService {
|
||||
},
|
||||
include: { priceTiers: true },
|
||||
});
|
||||
await this.auditService.log({ action: 'CREATE', entityType: 'Package', entityId: pkg.id, newData: { code: pkg.code, name: pkg.name } });
|
||||
return pkg;
|
||||
}
|
||||
|
||||
async update(id: string, dto: Partial<CreatePackageDto>) {
|
||||
const pkg = await this.prisma.travelPackage.findUnique({ where: { id } });
|
||||
if (!pkg) throw new NotFoundException('Package not found');
|
||||
return this.prisma.travelPackage.update({
|
||||
const updated = await this.prisma.travelPackage.update({
|
||||
where: { id },
|
||||
data: {
|
||||
...(dto.code && { code: dto.code }),
|
||||
@@ -307,6 +311,8 @@ export class PackagesService {
|
||||
},
|
||||
include: { priceTiers: true },
|
||||
});
|
||||
await this.auditService.log({ action: 'UPDATE', entityType: 'Package', entityId: id, newData: { code: dto.code, name: dto.name } });
|
||||
return updated;
|
||||
}
|
||||
|
||||
async addTier(packageId: string, dto: CreatePriceTierDto) {
|
||||
@@ -353,19 +359,24 @@ export class PackagesService {
|
||||
await this.prisma.packageInquiry.deleteMany({ where: { packageId: id } });
|
||||
await this.prisma.packagePriceTier.deleteMany({ where: { packageId: id } });
|
||||
await this.prisma.travelPackage.delete({ where: { id } });
|
||||
await this.auditService.log({ action: 'DELETE', entityType: 'Package', entityId: id });
|
||||
return { deleted: true };
|
||||
}
|
||||
|
||||
async activate(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: 'ACTIVE' } });
|
||||
const activated = await this.prisma.travelPackage.update({ where: { id }, data: { status: 'ACTIVE' } });
|
||||
await this.auditService.log({ action: 'UPDATE', entityType: 'Package', entityId: id, newData: { status: 'ACTIVE' } });
|
||||
return activated;
|
||||
}
|
||||
|
||||
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' } });
|
||||
const deactivated = await this.prisma.travelPackage.update({ where: { id }, data: { status: 'DRAFT' } });
|
||||
await this.auditService.log({ action: 'UPDATE', entityType: 'Package', entityId: id, newData: { status: 'DRAFT' } });
|
||||
return deactivated;
|
||||
}
|
||||
|
||||
async book(dto: BookPackageDto, passengerId?: string) {
|
||||
@@ -478,7 +489,7 @@ export class PackagesService {
|
||||
paidChildFareMinor: adultFareMinor,
|
||||
childFareNote: `First child per adult travels free (no seat); additional children pay full adult fare`,
|
||||
totalMinor,
|
||||
currency: 'ETB',
|
||||
currency: booking.displayCurrency,
|
||||
displayCurrency,
|
||||
displayTotalMinor,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user