diff --git a/apps/core-rest-api/src/app/adapters/controllers/api/use-cases/appointment/update-appointment/output.dto.ts b/apps/core-rest-api/src/app/adapters/controllers/api/use-cases/appointment/update-appointment/output.dto.ts index 07d4fdf..d381ea8 100644 --- a/apps/core-rest-api/src/app/adapters/controllers/api/use-cases/appointment/update-appointment/output.dto.ts +++ b/apps/core-rest-api/src/app/adapters/controllers/api/use-cases/appointment/update-appointment/output.dto.ts @@ -1,6 +1,60 @@ -import { IsString } from 'class-validator'; +import { PaymentMethod } from '@prisma/client'; +import { IsBoolean, IsDate, IsEnum, IsObject, IsString } from 'class-validator'; + +class UpdatedAppointmentInfoOutputDto { + @IsString() + id!: string; + + @IsString() + psychologistId!: string; + + @IsString() + patientId!: string; + + @IsDate() + date!: Date; + + @IsBoolean() + online!: boolean; + + @IsString() + clinicId!: string; + + @IsBoolean() + confirmed!: boolean; + + @IsDate() + confirmationDate!: Date | null; + + @IsBoolean() + cancelled!: boolean; + + @IsDate() + cancellationDate!: Date | null; + + @IsBoolean() + done!: boolean | null; + + @IsBoolean() + missed!: boolean | null; + + @IsBoolean() + paid!: boolean; + + @IsEnum(PaymentMethod) + paymentMethod!: PaymentMethod; + + @IsDate() + createdAt!: Date; + + @IsDate() + updatedAt!: Date | null; +} export class UpdateAppointmentControllerOutputDto { @IsString() message!: string; + + @IsObject({ each: true }) + updatedApointment!: UpdatedAppointmentInfoOutputDto } diff --git a/apps/core-rest-api/src/app/adapters/controllers/api/use-cases/appointment/update-appointment/update-appointment.controller.ts b/apps/core-rest-api/src/app/adapters/controllers/api/use-cases/appointment/update-appointment/update-appointment.controller.ts index 6e410e4..65a9322 100644 --- a/apps/core-rest-api/src/app/adapters/controllers/api/use-cases/appointment/update-appointment/update-appointment.controller.ts +++ b/apps/core-rest-api/src/app/adapters/controllers/api/use-cases/appointment/update-appointment/update-appointment.controller.ts @@ -28,9 +28,9 @@ export class UpdateAppointmentController { throw new BadRequestException('Must provide at least one field to update'); } - await this.updateAppointmentService.execute({ ...updateAppointmentDto, id }); + const updatedApointment = await this.updateAppointmentService.execute({ ...updateAppointmentDto, id }); - return { message: 'Appointment updated successfully' }; + return { message: 'Appointment updated successfully', updatedApointment }; } catch (error) { throw new GlobalAppHttpException(error); } diff --git a/apps/core-rest-api/src/app/adapters/database/repositories/appointment/postgres-prisma-orm-appointment-repository.ts b/apps/core-rest-api/src/app/adapters/database/repositories/appointment/postgres-prisma-orm-appointment-repository.ts index 60800ff..41a524a 100644 --- a/apps/core-rest-api/src/app/adapters/database/repositories/appointment/postgres-prisma-orm-appointment-repository.ts +++ b/apps/core-rest-api/src/app/adapters/database/repositories/appointment/postgres-prisma-orm-appointment-repository.ts @@ -112,7 +112,7 @@ export class PostgresqlPrismaOrmAppointmentRepository await this.postgresqlPrismaOrmService['appointment'].update(toPrismaEntity); } - async updateAppointment(newAppointmentInfo: UpdateAppointmentInfoInputDto): Promise { + async updateAppointment(newAppointmentInfo: UpdateAppointmentInfoInputDto): Promise { const oldAppointmentInfo = await this.findSingleAppointmentById(newAppointmentInfo.id); if (!oldAppointmentInfo) { @@ -123,7 +123,10 @@ export class PostgresqlPrismaOrmAppointmentRepository ...newAppointmentInfo, }); - await this.postgresqlPrismaOrmService['appointment'].update(toPrismaEntity); + const updatedPrismaAppointmentEntity = await this.postgresqlPrismaOrmService['appointment'].update(toPrismaEntity); + + return PostgresqlPrismaAppointmentMapper.toDomain(updatedPrismaAppointmentEntity); + } async deleteSingleAppointment(appointmentId: string): Promise { diff --git a/apps/core-rest-api/src/app/core/domains/appointment/entities/appointment/entity.ts b/apps/core-rest-api/src/app/core/domains/appointment/entities/appointment/entity.ts index ef33516..e8f7c75 100644 --- a/apps/core-rest-api/src/app/core/domains/appointment/entities/appointment/entity.ts +++ b/apps/core-rest-api/src/app/core/domains/appointment/entities/appointment/entity.ts @@ -14,6 +14,7 @@ export class AppointmentEntity extends AppointmentDto { this.missed = props.missed ?? null; this.cancellationDate = props.cancellationDate ?? null; this.paid = props.paid ?? false; + this.confirmationDate = props.confirmationDate ?? null; } public get getId(): string { diff --git a/apps/core-rest-api/src/app/core/domains/appointment/repositories/database-in-memory-repository.ts b/apps/core-rest-api/src/app/core/domains/appointment/repositories/database-in-memory-repository.ts index ce57cb0..9de333b 100644 --- a/apps/core-rest-api/src/app/core/domains/appointment/repositories/database-in-memory-repository.ts +++ b/apps/core-rest-api/src/app/core/domains/appointment/repositories/database-in-memory-repository.ts @@ -97,7 +97,7 @@ export class InMemoryAppointmentDatabaseRepository async updateAppointment( newAppointmentInfo: UpdateAppointmentDto, - ): Promise { + ): Promise { const oldAppointmentInfo = await this.findSingleAppointmentById( newAppointmentInfo.id, ); @@ -116,6 +116,8 @@ export class InMemoryAppointmentDatabaseRepository }); this.appointments[appointmentIndex] = updatedAppointment; + + return updatedAppointment } async deleteSingleAppointment(appointmentId: string): Promise { diff --git a/apps/core-rest-api/src/app/core/domains/appointment/repositories/database-repository.ts b/apps/core-rest-api/src/app/core/domains/appointment/repositories/database-repository.ts index 46adde7..d7b9b44 100644 --- a/apps/core-rest-api/src/app/core/domains/appointment/repositories/database-repository.ts +++ b/apps/core-rest-api/src/app/core/domains/appointment/repositories/database-repository.ts @@ -23,6 +23,6 @@ export abstract class AppointmentDatabaseRepository { ): Promise; abstract updateAppointment( newAppointmentInfo: UpdateAppointmentDto - ): Promise; + ): Promise; abstract deleteSingleAppointment(appointmentId: string): Promise; } diff --git a/apps/core-rest-api/src/app/core/domains/appointment/use-cases/update-single-appointment/update-appointment.service.ts b/apps/core-rest-api/src/app/core/domains/appointment/use-cases/update-single-appointment/update-appointment.service.ts index 5237dab..f380038 100644 --- a/apps/core-rest-api/src/app/core/domains/appointment/use-cases/update-single-appointment/update-appointment.service.ts +++ b/apps/core-rest-api/src/app/core/domains/appointment/use-cases/update-single-appointment/update-appointment.service.ts @@ -2,13 +2,14 @@ import { NotFoundException } from '@nestjs/common'; import { plainToInstance } from 'class-transformer'; import { APPOINTMENT_ERROR_MESSAGES } from '../../../../../shared/errors/error-messages'; import { applicationValidateOrReject } from '../../../../../shared/validators/validate-or-reject'; +import { AppointmentEntity } from '../../entities/appointment/entity'; import { AppointmentDatabaseRepository } from '../../repositories/database-repository'; import { UpdateAppointmentDto } from './update-appointment-dto'; export class UpdateAppointmentService { constructor(private appointmentDatabaseRepository: AppointmentDatabaseRepository) {} - async execute(newAppointmentInfo: UpdateAppointmentDto): Promise { + async execute(newAppointmentInfo: UpdateAppointmentDto): Promise { // Validate props const updateAppointmentDateDtoInstance = plainToInstance( @@ -26,6 +27,6 @@ export class UpdateAppointmentService { throw new NotFoundException(APPOINTMENT_ERROR_MESSAGES['APPOINTMENT_NOT_FOUND']); } - await this.appointmentDatabaseRepository.updateAppointment(newAppointmentInfo); + return await this.appointmentDatabaseRepository.updateAppointment(newAppointmentInfo); } }