commit working state
Too many changes to split them up. This commit contains roughly two months worth of work. This commit introduces the first aggregate and rewrites the ticket system to follow DDD patterns. It adds Spartan NG as the new component library. TanStack Query to replace GraphQL. Oh and Prisma is almost over as well.
This commit is contained in:
+70
@@ -0,0 +1,70 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
Inject,
|
||||
Injectable,
|
||||
Logger,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import {
|
||||
PATIENT_PROVIDER,
|
||||
PatientProvider,
|
||||
} from '../domain/ports/patient-provider.interface';
|
||||
import {
|
||||
TOUR_PROVIDER,
|
||||
TourProvider,
|
||||
} from '../domain/ports/tour-provider.interface';
|
||||
import { Ticket, TicketId } from '../domain/ticket.entity';
|
||||
import {
|
||||
TICKET_REPOSITORY,
|
||||
TicketRepository,
|
||||
} from '../domain/ticket.repository.interface';
|
||||
|
||||
export interface CreateTicketCommand {
|
||||
patientId: string;
|
||||
initialTourId?: string;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class CreateTicketUseCase {
|
||||
private readonly logger = new Logger(CreateTicketUseCase.name);
|
||||
|
||||
constructor(
|
||||
@Inject(TICKET_REPOSITORY) private readonly ticketRepo: TicketRepository,
|
||||
@Inject(TOUR_PROVIDER) private readonly tourProvider: TourProvider,
|
||||
@Inject(PATIENT_PROVIDER) private readonly patientProvider: PatientProvider,
|
||||
) {}
|
||||
|
||||
async execute(command: CreateTicketCommand): Promise<string> {
|
||||
const newTicketId = new TicketId(uuidv4());
|
||||
|
||||
const ticket = Ticket.create(newTicketId, command.patientId);
|
||||
|
||||
if (command.patientId) {
|
||||
const patient = await this.patientProvider.findPatientById(
|
||||
command.patientId,
|
||||
);
|
||||
if (patient) {
|
||||
ticket.updatePatientData(patient);
|
||||
}
|
||||
}
|
||||
|
||||
if (command.initialTourId) {
|
||||
const tour = await this.tourProvider.findTourById(command.initialTourId);
|
||||
if (!tour)
|
||||
throw new NotFoundException(
|
||||
`initial tour ${command.initialTourId} not found`,
|
||||
);
|
||||
|
||||
if (tour.patientId !== command.patientId) {
|
||||
throw new BadRequestException(`Patient mismatch`);
|
||||
}
|
||||
|
||||
ticket.assignTour(tour);
|
||||
}
|
||||
|
||||
await this.ticketRepo.save(ticket);
|
||||
|
||||
return newTicketId.value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user