Skip to content

Commit

Permalink
add patient edit endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
artweb11 committed Nov 17, 2023
1 parent 4e59310 commit 90d2eb6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/modules/patient-svc/dto/patient.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ export class CreatePatientDto {
city?: string;
}

export class EditPatientDto extends CreatePatientDto {
@IsNotEmpty()
@IsUUID()
@IsString()
id: string;
}

export class PatientResponseDto {
@IsNotEmpty()
@IsUUID()
Expand Down
14 changes: 13 additions & 1 deletion src/modules/patient-svc/patient-svc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -36,6 +36,18 @@ export class PatientSvcService {
return await this.patientRepository.save(patient);
}

async updatePatient(patientDto: EditPatientDto): Promise<Patient> {
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
*/
Expand Down
12 changes: 12 additions & 0 deletions src/modules/payer-svc/payer-svc.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<PatientResponseDto> {
return await this.patientService.updatePatient(editPatientAccountDto);
}

@Post('send-invite')
@Roles(UserRole.PAYER)
@ApiOperation({
Expand Down

0 comments on commit 90d2eb6

Please sign in to comment.