upd: examination type add service_ids
This commit is contained in:
@ -7,6 +7,7 @@ import CommonHelper from "../helpers/common";
|
|||||||
import { ReturnHelper } from "../helpers/express/return";
|
import { ReturnHelper } from "../helpers/express/return";
|
||||||
import { Language } from "../langs/lang";
|
import { Language } from "../langs/lang";
|
||||||
import { ExaminationTypeModel } from "../model/examination_type";
|
import { ExaminationTypeModel } from "../model/examination_type";
|
||||||
|
import { ServiceModel } from "../model/service";
|
||||||
import { OrmHelper } from "../helpers/orm";
|
import { OrmHelper } from "../helpers/orm";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
|
|
||||||
@ -48,6 +49,7 @@ export class ExaminationTypeController {
|
|||||||
|
|
||||||
const res_count = query;
|
const res_count = query;
|
||||||
const res_list = query
|
const res_list = query
|
||||||
|
.leftJoinAndSelect("ExaminationType.services", "services")
|
||||||
.orderBy("ExaminationType." + param.order_field, param.order_direction)
|
.orderBy("ExaminationType." + param.order_field, param.order_direction)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.limit(limit);
|
.limit(limit);
|
||||||
@ -82,6 +84,7 @@ export class ExaminationTypeController {
|
|||||||
const schema = Joi.object().keys({
|
const schema = Joi.object().keys({
|
||||||
name: Joi.string().max(256).required().label("Name"),
|
name: Joi.string().max(256).required().label("Name"),
|
||||||
status: Joi.string().required().label("Status"),
|
status: Joi.string().required().label("Status"),
|
||||||
|
service_ids: Joi.array().items(Joi.string().uuid()).optional().label("Service IDs"),
|
||||||
});
|
});
|
||||||
|
|
||||||
let param: any = await schema.validateAsync(req.body);
|
let param: any = await schema.validateAsync(req.body);
|
||||||
@ -90,9 +93,18 @@ export class ExaminationTypeController {
|
|||||||
let exist = await ExaminationTypeModel.list(filter).then((q) => q.getOne());
|
let exist = await ExaminationTypeModel.list(filter).then((q) => q.getOne());
|
||||||
if (exist) throw { message: "Examination Type " + Language.lang.failed_duplicate };
|
if (exist) throw { message: "Examination Type " + Language.lang.failed_duplicate };
|
||||||
|
|
||||||
|
let services: any[] = [];
|
||||||
|
if (param.service_ids && param.service_ids.length > 0) {
|
||||||
|
for (const serviceId of param.service_ids) {
|
||||||
|
const svc = await ServiceModel.list({ id: serviceId }).then((q) => q.getOne());
|
||||||
|
if (svc) services.push(svc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let examinationType = new ExaminationType();
|
let examinationType = new ExaminationType();
|
||||||
examinationType.name = param.name;
|
examinationType.name = param.name;
|
||||||
examinationType.status = param.status;
|
examinationType.status = param.status;
|
||||||
|
examinationType.services = services;
|
||||||
examinationType.created_by = req.auth.data.name;
|
examinationType.created_by = req.auth.data.name;
|
||||||
examinationType.updated_by = req.auth.data.name;
|
examinationType.updated_by = req.auth.data.name;
|
||||||
await queryRunner.manager.save(examinationType);
|
await queryRunner.manager.save(examinationType);
|
||||||
@ -123,7 +135,8 @@ export class ExaminationTypeController {
|
|||||||
|
|
||||||
let param: any = await schema.validateAsync(req.params);
|
let param: any = await schema.validateAsync(req.params);
|
||||||
|
|
||||||
let examinationType = await ExaminationTypeModel.list({ "ExaminationType.id": param.id }).then((q) => q.getOne());
|
let examinationType = await ExaminationTypeModel.list({ "ExaminationType.id": param.id })
|
||||||
|
.then((q) => q.leftJoinAndSelect("ExaminationType.services", "services").getOne());
|
||||||
|
|
||||||
if (!examinationType) throw { message: "Examination Type Not Found" };
|
if (!examinationType) throw { message: "Examination Type Not Found" };
|
||||||
|
|
||||||
@ -152,6 +165,7 @@ export class ExaminationTypeController {
|
|||||||
id: Joi.string().uuid().required().label("Examination Type ID"),
|
id: Joi.string().uuid().required().label("Examination Type ID"),
|
||||||
name: Joi.string().max(256).required().label("Name"),
|
name: Joi.string().max(256).required().label("Name"),
|
||||||
status: Joi.string().required().label("Status"),
|
status: Joi.string().required().label("Status"),
|
||||||
|
service_ids: Joi.array().items(Joi.string().uuid()).optional().label("Service IDs"),
|
||||||
});
|
});
|
||||||
|
|
||||||
let param: any = await schema.validateAsync(req.body);
|
let param: any = await schema.validateAsync(req.body);
|
||||||
@ -160,12 +174,22 @@ export class ExaminationTypeController {
|
|||||||
let exist = await ExaminationTypeModel.list(filter).then((q) => q.getOne());
|
let exist = await ExaminationTypeModel.list(filter).then((q) => q.getOne());
|
||||||
if (exist && exist.id != param.id) throw { message: "Examination Type " + Language.lang.failed_duplicate };
|
if (exist && exist.id != param.id) throw { message: "Examination Type " + Language.lang.failed_duplicate };
|
||||||
|
|
||||||
let examinationType = await ExaminationTypeModel.list({ "ExaminationType.id": param.id }).then((q) => q.getOne());
|
let examinationType = await ExaminationTypeModel.list({ "ExaminationType.id": param.id })
|
||||||
|
.then((q) => q.leftJoinAndSelect("ExaminationType.services", "services").getOne());
|
||||||
|
|
||||||
if (!examinationType) throw { message: "Examination Type " + Language.lang.failed_not_found };
|
if (!examinationType) throw { message: "Examination Type " + Language.lang.failed_not_found };
|
||||||
|
|
||||||
|
let services: any[] = [];
|
||||||
|
if (param.service_ids && param.service_ids.length > 0) {
|
||||||
|
for (const serviceId of param.service_ids) {
|
||||||
|
const svc = await ServiceModel.list({ id: serviceId }).then((q) => q.getOne());
|
||||||
|
if (svc) services.push(svc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
examinationType.name = param.name;
|
examinationType.name = param.name;
|
||||||
examinationType.status = param.status;
|
examinationType.status = param.status;
|
||||||
|
examinationType.services = services;
|
||||||
examinationType.updated_by = req.auth.data.name;
|
examinationType.updated_by = req.auth.data.name;
|
||||||
await queryRunner.manager.save(examinationType);
|
await queryRunner.manager.save(examinationType);
|
||||||
|
|
||||||
|
|||||||
@ -171,7 +171,8 @@ const doc = {
|
|||||||
},
|
},
|
||||||
examinationType: {
|
examinationType: {
|
||||||
$name: "Examination Type name",
|
$name: "Examination Type name",
|
||||||
$status: { "@enum": ["Y", "N"] }
|
$status: { "@enum": ["Y", "N"] },
|
||||||
|
$service_ids: ["uuid-string"]
|
||||||
},
|
},
|
||||||
examinationDetail: {
|
examinationDetail: {
|
||||||
$name: "Examination Detail name",
|
$name: "Examination Detail name",
|
||||||
|
|||||||
Reference in New Issue
Block a user