Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop

This commit is contained in:
Kittapath 2024-02-01 11:34:35 +07:00
commit 22b80868d4

View file

@ -24,7 +24,7 @@ import { PosType } from "../entities/PosType";
import { PosLevel } from "../entities/PosLevel"; import { PosLevel } from "../entities/PosLevel";
import { CreatePosDict, PosDict } from "../entities/PosDict"; import { CreatePosDict, PosDict } from "../entities/PosDict";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import { In, Like } from "typeorm"; import { In, IsNull, Like } from "typeorm";
import { CreatePosMaster, PosMaster } from "../entities/PosMaster"; import { CreatePosMaster, PosMaster } from "../entities/PosMaster";
import { OrgRevision } from "../entities/OrgRevision"; import { OrgRevision } from "../entities/OrgRevision";
import { OrgRoot } from "../entities/OrgRoot"; import { OrgRoot } from "../entities/OrgRoot";
@ -731,23 +731,44 @@ export class PositionController extends Controller {
) { ) {
try { try {
let typeCondition: any = {}; let typeCondition: any = {};
let checkChildConditions: any = {};
if (body.type === 0) { if (body.type === 0) {
typeCondition = { typeCondition = {
orgRootId: body.id, orgRootId: body.id,
}; };
if (!body.isAll) {
checkChildConditions = {
orgChild1Id: IsNull(),
};
}
} else if (body.type === 1) { } else if (body.type === 1) {
typeCondition = { typeCondition = {
orgChild1Id: body.id, orgChild1Id: body.id,
}; };
if (!body.isAll) {
checkChildConditions = {
orgChild2Id: IsNull(),
};
}
} else if (body.type === 2) { } else if (body.type === 2) {
typeCondition = { typeCondition = {
orgChild2Id: body.id, orgChild2Id: body.id,
}; };
if (!body.isAll) {
checkChildConditions = {
orgChild3Id: IsNull(),
};
}
} else if (body.type === 3) { } else if (body.type === 3) {
typeCondition = { typeCondition = {
orgChild3Id: body.id, orgChild3Id: body.id,
}; };
if (!body.isAll) {
checkChildConditions = {
orgChild4Id: IsNull(),
};
}
} else if (body.type === 4) { } else if (body.type === 4) {
typeCondition = { typeCondition = {
orgChild4Id: body.id, orgChild4Id: body.id,
@ -755,7 +776,10 @@ export class PositionController extends Controller {
} }
const posMaster = await this.posMasterRepository.find({ const posMaster = await this.posMasterRepository.find({
where: typeCondition, where: {
...typeCondition,
...checkChildConditions,
},
}); });
if (!posMaster || posMaster.length === 0) { if (!posMaster || posMaster.length === 0) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");