import {inject} from '@loopback/core'; import { param, patch, requestBody, } from '@loopback/rest'; import {STATUS_CODE, SuccessResponse} from '@sourcefuse-npm/alivio-lib'; import { Appointment, PatientOnboardingService } from '@sourcefuse-npm/patient-facade'; import {authenticate, STRATEGY} from 'loopback4-authentication'; import {authorize} from 'loopback4-authorization'; import { UserSecondaryData } from '../models'; import {AppointmentFeedbackService, CheckInUsersService} from '../services'; export class Appointmentontroller { constructor( @inject('services.AppointmentFeedbackService') public appointmentFeedbackService: AppointmentFeedbackService, @inject('services.CheckInUsersService') public usersService: CheckInUsersService, @inject('services.PatientOnboardingService') protected patientOnbService: PatientOnboardingService, ) {} @authenticate(STRATEGY.BEARER, { passReqToCallback: true, }) @authorize({permissions: ['*']}) @patch(`appointments/{id}`, { responses: { [STATUS_CODE.NO_CONTENT]: { description: 'Appointment PATCH', }, }, }) async replaceById( @param.path.number('id') id: number, @requestBody() appointment: Partial, @param.header.string('Authorization') token?: string, ): Promise { await this.appointmentFeedbackService.updateAppoinement( id, appointment, token, ); const data : Partial={ secondaryEmail: appointment.email, secondaryPhone: appointment.phone }; const patientResp = await this.patientOnbService.findPatientById( appointment.patientId ?? 0, token, ); this.usersService.updateUserSecondory(patientResp.userId ?? 0, data, token); return new SuccessResponse({ success: true, }); } }