fix examination type create and update

This commit is contained in:
avicenan
2026-04-27 17:39:16 +07:00
parent 8268639a08
commit 72a1eb672d

View File

@ -1,4 +1,4 @@
import { ExaminationType, Paging } from "entity"; import { ExaminationType, Paging, Service } from "entity";
import { NextFunction, Response } from "express"; import { NextFunction, Response } from "express";
import { Request } from "express-jwt"; import { Request } from "express-jwt";
import Joi from "joi"; import Joi from "joi";
@ -10,6 +10,7 @@ import { ExaminationTypeModel } from "../model/examination_type";
import { ServiceModel } from "../model/service"; import { ServiceModel } from "../model/service";
import { OrmHelper } from "../helpers/orm"; import { OrmHelper } from "../helpers/orm";
import moment from "moment"; import moment from "moment";
import { In } from "typeorm";
const log: Logger<ILogObj> = new Logger({ const log: Logger<ILogObj> = new Logger({
name: "[ExaminationTypeController]", name: "[ExaminationTypeController]",
@ -93,12 +94,10 @@ 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[] = []; let services: Service[] = [];
if (param.service_ids && param.service_ids.length > 0) { if (param.service_ids && param.service_ids.length > 0) {
for (const serviceId of param.service_ids) { services = await queryRunner.manager.getRepository(Service).find({ where: { id: In(param.service_ids) } });
const svc = await ServiceModel.list({ id: serviceId }).then((q) => q.getOne()); if (services.length != param.service_ids.length) throw { message: "Service not found" };
if (svc) services.push(svc);
}
} }
let examinationType = new ExaminationType(); let examinationType = new ExaminationType();
@ -179,12 +178,10 @@ export class ExaminationTypeController {
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[] = []; let services: Service[] = [];
if (param.service_ids && param.service_ids.length > 0) { if (param.service_ids && param.service_ids.length > 0) {
for (const serviceId of param.service_ids) { services = await queryRunner.manager.getRepository(Service).find({ where: { id: In(param.service_ids) } });
const svc = await ServiceModel.list({ id: serviceId }).then((q) => q.getOne()); if (services.length != param.service_ids.length) throw { message: "Service not found" };
if (svc) services.push(svc);
}
} }
examinationType.name = param.name; examinationType.name = param.name;