diff --git a/src/controllers/CommandOperatorController.ts b/src/controllers/CommandOperatorController.ts index f1cac92a..1a461ab3 100644 --- a/src/controllers/CommandOperatorController.ts +++ b/src/controllers/CommandOperatorController.ts @@ -187,13 +187,13 @@ export class CommandOperatorController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบเจ้าหน้าที่ดำเนินการ"); } - // 2. ห้ามลบ orderNo = 1 - if (operator.orderNo === 1) { - throw new HttpError( - HttpStatusCode.BAD_REQUEST, - "ไม่สามารถลบเจ้าหน้าที่ลำดับที่ 1 ได้" - ); - } + // // 2. ห้ามลบ orderNo = 1 + // if (operator.orderNo === 1) { + // throw new HttpError( + // HttpStatusCode.BAD_REQUEST, + // "ไม่สามารถลบเจ้าหน้าที่ลำดับที่ 1 ได้" + // ); + // } const removedOrderNo = operator.orderNo; diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 83e5719c..aaa1e7a4 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -7151,75 +7151,174 @@ export class OrganizationController extends Controller { */ @Get("root/search/sort") async searchSortRootLevelType(@Request() request: RequestWithUser) { - const root1 = await this.orgRootRepository.find({ - where: { - orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, - DEPARTMENT_CODE: Not("50"), - }, - order: { isDeputy: "DESC", orgRootOrder: "ASC" }, - select: ["orgRootName"], - }); - const root2 = await this.orgRootRepository.find({ - where: { - orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, - DEPARTMENT_CODE: "50", - }, - order: { orgRootName: "ASC" }, - select: ["orgRootName"], - }); - const root = [...root1, ...root2]; + // const root1 = await this.orgRootRepository.find({ + // where: { + // orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + // DEPARTMENT_CODE: Not("50"), + // }, + // order: { isDeputy: "DESC", orgRootOrder: "ASC" }, + // select: ["orgRootName"], + // }); + // const root2 = await this.orgRootRepository.find({ + // where: { + // orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + // DEPARTMENT_CODE: "50", + // }, + // order: { orgRootName: "ASC" }, + // select: ["orgRootName"], + // }); + // const root = [...root1, ...root2]; + + // const child1 = await this.child1Repository.find({ + // where: { + // orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + // }, + // order: { orgChild1Order: "ASC" }, + // select: ["orgChild1Name"], + // }); + // const child2 = await this.child2Repository.find({ + // where: { + // orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + // }, + // order: { orgChild2Order: "ASC" }, + // select: ["orgChild2Name"], + // }); + // const child3 = await this.child3Repository.find({ + // where: { + // orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + // }, + // order: { orgChild3Order: "ASC" }, + // select: ["orgChild3Name"], + // }); + // const child4 = await this.child4Repository.find({ + // where: { + // orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + // }, + // order: { orgChild4Order: "ASC" }, + // select: ["orgChild4Name"], + // }); + // const hospital = await this.child1Repository.find({ + // where: [ + // { + // orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + // orgRoot: { isDeputy: true }, + // }, + // { + // orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + // orgChild1RankSub: "HOSPITAL", + // }, + // ], + // select: ["orgChild1Name"], + // }); + // const posType = await this.posTypeRepository.find({ + // order: { posTypeRank: "DESC" }, + // select: ["posTypeName"], + // }); + // const posLevel = await this.posLevelRepository.find({ + // order: { posLevelRank: "DESC" }, + // select: ["posLevelName"], + // }); + + const [ + roots, + child1, + child2, + child3, + child4, + hospital, + posType, + posLevel, + ] = await Promise.all([ + + // ===== ROOT ===== + this.orgRootRepository + .createQueryBuilder("root") + .innerJoin("root.orgRevision", "rev") + .select([ + "root.orgRootName AS orgRootName", + ]) + .where("rev.orgRevisionIsDraft = false") + .andWhere("rev.orgRevisionIsCurrent = true") + .orderBy( + "CASE WHEN root.DEPARTMENT_CODE = '50' THEN 1 ELSE 0 END", + "ASC", + ) + .addOrderBy("root.isDeputy", "DESC") + .addOrderBy("root.orgRootOrder", "ASC") + .addOrderBy("root.orgRootName", "ASC") + .getRawMany(), + + // ===== CHILD 1 ===== + this.child1Repository + .createQueryBuilder("c1") + .innerJoin("c1.orgRevision", "rev") + .select("c1.orgChild1Name", "orgChild1Name") + .where("rev.orgRevisionIsDraft = false") + .andWhere("rev.orgRevisionIsCurrent = true") + .orderBy("c1.orgChild1Order", "ASC") + .getRawMany(), + + // ===== CHILD 2 ===== + this.child2Repository + .createQueryBuilder("c2") + .innerJoin("c2.orgRevision", "rev") + .select("c2.orgChild2Name", "orgChild2Name") + .where("rev.orgRevisionIsDraft = false") + .andWhere("rev.orgRevisionIsCurrent = true") + .orderBy("c2.orgChild2Order", "ASC") + .getRawMany(), + + // ===== CHILD 3 ===== + this.child3Repository + .createQueryBuilder("c3") + .innerJoin("c3.orgRevision", "rev") + .select("c3.orgChild3Name", "orgChild3Name") + .where("rev.orgRevisionIsDraft = false") + .andWhere("rev.orgRevisionIsCurrent = true") + .orderBy("c3.orgChild3Order", "ASC") + .getRawMany(), + + // ===== CHILD 4 ===== + this.child4Repository + .createQueryBuilder("c4") + .innerJoin("c4.orgRevision", "rev") + .select("c4.orgChild4Name", "orgChild4Name") + .where("rev.orgRevisionIsDraft = false") + .andWhere("rev.orgRevisionIsCurrent = true") + .orderBy("c4.orgChild4Order", "ASC") + .getRawMany(), + + // ===== HOSPITAL ===== + this.child1Repository + .createQueryBuilder("c1") + .innerJoin("c1.orgRevision", "rev") + .leftJoin("c1.orgRoot", "root") + .select("c1.orgChild1Name", "orgChild1Name") + .where("rev.orgRevisionIsDraft = false") + .andWhere("rev.orgRevisionIsCurrent = true") + .andWhere( + "(root.isDeputy = true OR c1.orgChild1RankSub = :rank)", + { rank: "HOSPITAL" }, + ) + .getRawMany(), + + // ===== POSITION TYPE ===== + this.posTypeRepository + .createQueryBuilder("pt") + .select("pt.posTypeName", "posTypeName") + .orderBy("pt.posTypeRank", "DESC") + .getRawMany(), + + // ===== POSITION LEVEL ===== + this.posLevelRepository + .createQueryBuilder("pl") + .select("pl.posLevelName", "posLevelName") + .orderBy("pl.posLevelRank", "DESC") + .getRawMany(), + ]); - const child1 = await this.child1Repository.find({ - where: { - orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, - }, - order: { orgChild1Order: "ASC" }, - select: ["orgChild1Name"], - }); - const child2 = await this.child2Repository.find({ - where: { - orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, - }, - order: { orgChild2Order: "ASC" }, - select: ["orgChild2Name"], - }); - const child3 = await this.child3Repository.find({ - where: { - orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, - }, - order: { orgChild3Order: "ASC" }, - select: ["orgChild3Name"], - }); - const child4 = await this.child4Repository.find({ - where: { - orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, - }, - order: { orgChild4Order: "ASC" }, - select: ["orgChild4Name"], - }); - const hospital = await this.child1Repository.find({ - where: [ - { - orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, - orgRoot: { isDeputy: true }, - }, - { - orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, - orgChild1RankSub: "HOSPITAL", - }, - ], - select: ["orgChild1Name"], - }); - const posType = await this.posTypeRepository.find({ - order: { posTypeRank: "DESC" }, - select: ["posTypeName"], - }); - const posLevel = await this.posLevelRepository.find({ - order: { posLevelRank: "DESC" }, - select: ["posLevelName"], - }); return new HttpSuccess({ - root: root.map((x) => x.orgRootName), + root: roots.map((x) => x.orgRootName), child1: child1.map((x) => x.orgChild1Name), child2: child2.map((x) => x.orgChild2Name), child3: child3.map((x) => x.orgChild3Name), diff --git a/src/controllers/ProfileSalaryTempController.ts b/src/controllers/ProfileSalaryTempController.ts index 6ea1713c..33d6a835 100644 --- a/src/controllers/ProfileSalaryTempController.ts +++ b/src/controllers/ProfileSalaryTempController.ts @@ -1431,10 +1431,10 @@ export class ProfileSalaryTempController extends Controller { profileEmployeeId: x.profileEmployeeId, dateStart: x.commandDateAffect, dateEnd: null, - posNo: x.posNo, + posNo: `${x.posNoAbb} ${x.posNo}`, position: x.positionName, commandId: x.commandId, - refCommandNo: x.commandNo, + refCommandNo: `${x.commandNo}/${x.commandYear}`, refCommandDate: x.commandDateAffect, status: false, isDeleted: false, @@ -1454,8 +1454,8 @@ export class ProfileSalaryTempController extends Controller { dateStart: x.commandDateAffect, dateEnd: null, commandId: x.commandId, - commandNo: x.commandNo, - commandName: x.commandName, + commandNo: `${x.commandNo}/${x.commandYear}`, + commandName: x.commandName ?? "ให้ช่วยราชการ", refCommandDate: x.commandDateSign, refId: x.refId, status: "DONE",