#Need help with this route

1 messages · Page 1 of 1 (latest)

supple rampart
#

model:

@Schema()
export class Patient {
  @Prop({ required: true })
  firstName: string;
  @Prop({ required: true })
  lastName: string;
  @Prop({ required: true })
  email: string;
  @Prop({ required: true })
  phone: string;
  @Prop({ required: true })
  birthDate: Date;
  @Prop({ required: true })
  address: string;
  @Prop({ required: true })
  job: string;
  @Prop({ required: true })
  comeFrom: string;
  @Prop({ required: true })
  married: boolean;
  @Prop({ required: true })
  kids: boolean;
  @Prop({ required: true })
  whyTheyCome: string;
  @Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'Anamnese' })
  anamnese: Anamnese;
  @Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'Script' })
  script: Script[];
  @Prop({ default: Date.now() })
  createdAt: Date;
  @Prop({ default: Date.now() })
  updatedAt: Date;
}
#

service:

async update(id: string, patient: Patient): Promise<Patient> {
    return this.patientModel.findByIdAndUpdate(id, patient, { new: true });
  }
#

controller:

@Put('/update-patient/:id')
  async updatePatient(
    @Res() response,
    @Body() @Param('id') id: string,
    patient: Patient,
  ) {
    const updatedPatient = await this.patientService.update(id, patient);
    return response.status(HttpStatus.OK).json(updatedPatient);
  }