69 lines
1.9 KiB
TypeScript
69 lines
1.9 KiB
TypeScript
/**
|
|
* BookingService (Domain Service)
|
|
*
|
|
* Business logic for booking management
|
|
*/
|
|
|
|
import { Injectable } from '@nestjs/common';
|
|
import { Booking, BookingContainer } from '../entities/booking.entity';
|
|
import { BookingNumber } from '../value-objects/booking-number.vo';
|
|
import { BookingStatus } from '../value-objects/booking-status.vo';
|
|
import { BookingRepository } from '../ports/out/booking.repository';
|
|
import { RateQuoteRepository } from '../ports/out/rate-quote.repository';
|
|
import { v4 as uuidv4 } from 'uuid';
|
|
|
|
export interface CreateBookingInput {
|
|
rateQuoteId: string;
|
|
shipper: any;
|
|
consignee: any;
|
|
cargoDescription: string;
|
|
containers: any[];
|
|
specialInstructions?: string;
|
|
}
|
|
|
|
@Injectable()
|
|
export class BookingService {
|
|
constructor(
|
|
private readonly bookingRepository: BookingRepository,
|
|
private readonly rateQuoteRepository: RateQuoteRepository
|
|
) {}
|
|
|
|
/**
|
|
* Create a new booking
|
|
*/
|
|
async createBooking(input: CreateBookingInput): Promise<Booking> {
|
|
// Validate rate quote exists
|
|
const rateQuote = await this.rateQuoteRepository.findById(input.rateQuoteId);
|
|
if (!rateQuote) {
|
|
throw new Error(`Rate quote ${input.rateQuoteId} not found`);
|
|
}
|
|
|
|
// TODO: Get userId and organizationId from context
|
|
const userId = 'temp-user-id';
|
|
const organizationId = 'temp-org-id';
|
|
|
|
// Create booking entity
|
|
const booking = Booking.create({
|
|
id: uuidv4(),
|
|
userId,
|
|
organizationId,
|
|
rateQuoteId: input.rateQuoteId,
|
|
shipper: input.shipper,
|
|
consignee: input.consignee,
|
|
cargoDescription: input.cargoDescription,
|
|
containers: input.containers.map((c) => ({
|
|
id: uuidv4(),
|
|
type: c.type,
|
|
containerNumber: c.containerNumber,
|
|
vgm: c.vgm,
|
|
temperature: c.temperature,
|
|
sealNumber: c.sealNumber,
|
|
})),
|
|
specialInstructions: input.specialInstructions,
|
|
});
|
|
|
|
// Persist booking
|
|
return this.bookingRepository.save(booking);
|
|
}
|
|
}
|