From 90d2eb6eacd00326bbbc6aaae4c25ede1b70981d Mon Sep 17 00:00:00 2001 From: Bratu Sebastian Date: Fri, 17 Nov 2023 06:43:34 +0200 Subject: [PATCH] add patient edit endpoint --- src/modules/patient-svc/dto/patient.dto.ts | 7 +++++++ src/modules/patient-svc/patient-svc.service.ts | 14 +++++++++++++- src/modules/payer-svc/payer-svc.controller.ts | 12 ++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/modules/patient-svc/dto/patient.dto.ts b/src/modules/patient-svc/dto/patient.dto.ts index 3437d77..5a7f245 100644 --- a/src/modules/patient-svc/dto/patient.dto.ts +++ b/src/modules/patient-svc/dto/patient.dto.ts @@ -37,6 +37,13 @@ export class CreatePatientDto { city?: string; } +export class EditPatientDto extends CreatePatientDto { + @IsNotEmpty() + @IsUUID() + @IsString() + id: string; +} + export class PatientResponseDto { @IsNotEmpty() @IsUUID() diff --git a/src/modules/patient-svc/patient-svc.service.ts b/src/modules/patient-svc/patient-svc.service.ts index 76553ed..57d0f2d 100644 --- a/src/modules/patient-svc/patient-svc.service.ts +++ b/src/modules/patient-svc/patient-svc.service.ts @@ -8,7 +8,7 @@ import { _403, _404 } from '../../common/constants/errors'; import { Repository } from 'typeorm'; import { UserType } from '../../common/constants/enums'; import { Transaction } from '../smart-contract/entities/transaction.entity'; -import { CreatePatientDto, PatientResponseDto } from './dto/patient.dto'; +import { CreatePatientDto, EditPatientDto, PatientResponseDto } from './dto/patient.dto'; import { Patient } from './entities/patient.entity'; @Injectable() @@ -36,6 +36,18 @@ export class PatientSvcService { return await this.patientRepository.save(patient); } + async updatePatient(patientDto: EditPatientDto): Promise { + const patient = await this.patientRepository.findOne({ + where: { id: patientDto.id }, + }); + + const updateData = patientDto; + delete updateData.id; + await this.patientRepository.save( {...patient, ...updateData } ); + + return { ...patient,...updateData}; + } + /** * This function is used to find a patient by his/her phone number */ diff --git a/src/modules/payer-svc/payer-svc.controller.ts b/src/modules/payer-svc/payer-svc.controller.ts index 7225fb6..74bc1d0 100644 --- a/src/modules/payer-svc/payer-svc.controller.ts +++ b/src/modules/payer-svc/payer-svc.controller.ts @@ -23,6 +23,7 @@ import { _403, _404, _409 } from '../../common/constants/errors'; import { CachingService } from '../caching/caching.service'; import { CreatePatientDto, + EditPatientDto, PatientResponseDto, } from '../patient-svc/dto/patient.dto'; import { PatientSvcService } from '../patient-svc/patient-svc.service'; @@ -125,6 +126,17 @@ export class PayerSvcController { return await this.patientService.registerPatient(createPatientAccountDto); } + @Put('patient') + @Roles(UserRole.PAYER) + @ApiOperation({ + summary: 'This API is used update the Patient by PAYER.', + }) + async updatePatient( + @Body() editPatientAccountDto: EditPatientDto, + ): Promise { + return await this.patientService.updatePatient(editPatientAccountDto); + } + @Post('send-invite') @Roles(UserRole.PAYER) @ApiOperation({