diff --git a/src/controllers/doctor_schedule.ts b/src/controllers/doctor_schedule.ts index 3713651..c379294 100644 --- a/src/controllers/doctor_schedule.ts +++ b/src/controllers/doctor_schedule.ts @@ -1,4 +1,4 @@ -import { DoctorSchedule, Room, Paging } from "entity"; +import { DoctorSchedule, Room, User, Paging } from "entity"; import { NextFunction, Response } from "express"; import { Request } from "express-jwt"; import Joi from "joi"; @@ -94,11 +94,14 @@ export class DoctorScheduleController { let room = await OrmHelper.DB.getRepository(Room).findOne({ where: { id: param.room_id } }); if (!room) throw { message: "Room " + Language.lang.failed_not_found }; + let doctor = await OrmHelper.DB.getRepository(User).findOne({ where: { id: param.doctor_id } }); + if (!doctor) throw { message: "Doctor (User) " + Language.lang.failed_not_found }; + let doctorSchedule = new DoctorSchedule(); doctorSchedule.day = param.day; doctorSchedule.start_time = param.start_time; doctorSchedule.end_time = param.end_time; - doctorSchedule.doctor_id = param.doctor_id; + doctorSchedule.doctor = doctor; doctorSchedule.room = room; doctorSchedule.quota = param.quota || null; doctorSchedule.status = param.status; @@ -173,6 +176,9 @@ export class DoctorScheduleController { let room = await OrmHelper.DB.getRepository(Room).findOne({ where: { id: param.room_id } }); if (!room) throw { message: "Room " + Language.lang.failed_not_found }; + let doctor = await OrmHelper.DB.getRepository(User).findOne({ where: { id: param.doctor_id } }); + if (!doctor) throw { message: "Doctor (User) " + Language.lang.failed_not_found }; + let doctorSchedule = await DoctorScheduleModel.list({ id: param.id }).then((q) => q.getOne()); if (!doctorSchedule) throw { message: "Doctor Schedule " + Language.lang.failed_not_found }; @@ -180,7 +186,7 @@ export class DoctorScheduleController { doctorSchedule.day = param.day; doctorSchedule.start_time = param.start_time; doctorSchedule.end_time = param.end_time; - doctorSchedule.doctor_id = param.doctor_id; + doctorSchedule.doctor = doctor; doctorSchedule.room = room; doctorSchedule.quota = param.quota || null; doctorSchedule.status = param.status; diff --git a/src/helpers/orm.ts b/src/helpers/orm.ts index bd34cb3..a3008c6 100644 --- a/src/helpers/orm.ts +++ b/src/helpers/orm.ts @@ -1,7 +1,7 @@ import config from 'config'; import { DataSource } from "typeorm"; import { ILogObj, Logger } from 'tslog'; -import { Administrativu, Aldeia, District, Menu, Munisipo, Suco, Application, Nationality, Diagnosis, DiagnosticProcedure, Room, ServiceType, ServiceClass, Service, ServiceFare, ServicePackage, Department, DoctorSchedule } from 'entity' +import { Administrativu, Aldeia, District, Menu, Munisipo, Suco, Application, Nationality, Diagnosis, DiagnosticProcedure, Room, ServiceType, ServiceClass, Service, ServiceFare, ServicePackage, Department, DoctorSchedule, User, UserRole, HrmsEmployee } from 'entity' export class OrmHelper { static DB: DataSource = null @@ -20,7 +20,7 @@ export class OrmHelper { database: String(config.get("database.database")), synchronize: true, logging: config.get('database.logging'), - entities: [Menu, Administrativu, Aldeia, District, Munisipo, Suco, Application, Nationality, Diagnosis, DiagnosticProcedure, Room, ServiceType, ServiceClass, Service, ServiceFare, ServicePackage, Department, DoctorSchedule], + entities: [Menu, Administrativu, Aldeia, District, Munisipo, Suco, Application, Nationality, Diagnosis, DiagnosticProcedure, Room, ServiceType, ServiceClass, Service, ServiceFare, ServicePackage, Department, DoctorSchedule, User, UserRole, HrmsEmployee], subscribers: [], migrations: [], }) diff --git a/src/model/doctor_schedule.ts b/src/model/doctor_schedule.ts index 6b3db24..e40b82f 100644 --- a/src/model/doctor_schedule.ts +++ b/src/model/doctor_schedule.ts @@ -13,7 +13,9 @@ export class DoctorScheduleModel { whereVal = { ...whereVal, ...CommonHelper.handleQueryFilter(filter).whereVal }; } - var query = repo.createQueryBuilder("DoctorSchedule").leftJoinAndSelect("DoctorSchedule.room", "Room"); + var query = repo.createQueryBuilder("DoctorSchedule") + .leftJoinAndSelect("DoctorSchedule.doctor", "doctor") + .leftJoinAndSelect("DoctorSchedule.room", "Room"); if (whereAttr.length != 0) { query = query.where(whereAttr.join(" and "), whereVal); }