Skip to content

Commit

Permalink
debug(CC-119): wip
Browse files Browse the repository at this point in the history
  • Loading branch information
luana-v-santos committed Apr 16, 2024
1 parent d4f7724 commit df65cd3
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class PostgresqlPrismaOrmAppointmentRepository
await this.postgresqlPrismaOrmService['appointment'].update(toPrismaEntity);
}

async updateAppointment(newAppointmentInfo: UpdateAppointmentInfoInputDto): Promise<void> {
async updateAppointment(newAppointmentInfo: UpdateAppointmentInfoInputDto): Promise<AppointmentEntity> {
const oldAppointmentInfo = await this.findSingleAppointmentById(newAppointmentInfo.id);

if (!oldAppointmentInfo) {
Expand All @@ -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<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class InMemoryAppointmentDatabaseRepository

async updateAppointment(
newAppointmentInfo: UpdateAppointmentDto,
): Promise<void> {
): Promise<AppointmentEntity> {
const oldAppointmentInfo = await this.findSingleAppointmentById(
newAppointmentInfo.id,
);
Expand All @@ -116,6 +116,8 @@ export class InMemoryAppointmentDatabaseRepository
});

this.appointments[appointmentIndex] = updatedAppointment;

return updatedAppointment
}

async deleteSingleAppointment(appointmentId: string): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ export abstract class AppointmentDatabaseRepository {
): Promise<void>;
abstract updateAppointment(
newAppointmentInfo: UpdateAppointmentDto
): Promise<void>;
): Promise<AppointmentEntity>;
abstract deleteSingleAppointment(appointmentId: string): Promise<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
async execute(newAppointmentInfo: UpdateAppointmentDto): Promise<AppointmentEntity> {
// Validate props

const updateAppointmentDateDtoInstance = plainToInstance(
Expand All @@ -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);
}
}

0 comments on commit df65cd3

Please sign in to comment.