improvement: treatment exits contoll adde to appoinment remove action.
This commit is contained in:
@@ -63,6 +63,7 @@ export const ErrorCode = {
|
||||
CONFLICT: 'CONFLICT',
|
||||
CONFLICT_FUTURE_APPOINTMENTS: 'CONFLICT_FUTURE_APPOINTMENTS',
|
||||
APPOINTMENT_PATIENT_LOCKED: 'APPOINTMENT_PATIENT_LOCKED',
|
||||
APPOINTMENT_HAS_TREATMENT: 'APPOINTMENT_HAS_TREATMENT',
|
||||
BAD_REQUEST: 'BAD_REQUEST',
|
||||
INTERNAL_ERROR: 'INTERNAL_ERROR',
|
||||
} as const;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
ForbiddenException,
|
||||
HttpStatus,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
@@ -16,6 +17,7 @@ import { ListAppointmentsDto } from './dto/list-appointments.dto';
|
||||
import { UpdateAppointmentDto } from './dto/update-appointment.dto';
|
||||
import { TreatmentCatalogService } from '../treatment-catalog/treatment-catalog.service';
|
||||
import { hasEffectivePermission } from '../../common/membership-permissions';
|
||||
import { AppException, ErrorCode } from '../../common/errors';
|
||||
|
||||
const MS_PER_DAY = 86_400_000;
|
||||
|
||||
@@ -215,9 +217,7 @@ export class AppointmentsService {
|
||||
select: { id: true },
|
||||
});
|
||||
if (linkedTreatment) {
|
||||
throw new BadRequestException(
|
||||
'Cannot change the patient while a treatment is linked to this appointment',
|
||||
);
|
||||
throw new AppException(ErrorCode.APPOINTMENT_PATIENT_LOCKED, HttpStatus.CONFLICT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,13 +256,17 @@ export class AppointmentsService {
|
||||
|
||||
const existing = await this.prisma.appointment.findFirst({
|
||||
where: { id, organizationId },
|
||||
select: { id: true },
|
||||
select: { id: true, treatment: { select: { id: true } } },
|
||||
});
|
||||
|
||||
if (!existing) {
|
||||
throw new NotFoundException('Appointment not found');
|
||||
}
|
||||
|
||||
if (existing.treatment) {
|
||||
throw new AppException(ErrorCode.APPOINTMENT_HAS_TREATMENT, HttpStatus.CONFLICT);
|
||||
}
|
||||
|
||||
await this.prisma.appointment.delete({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user