diff --git a/src/controllers/EmployeePositionController.ts b/src/controllers/EmployeePositionController.ts index 071186a3..1cb09d65 100644 --- a/src/controllers/EmployeePositionController.ts +++ b/src/controllers/EmployeePositionController.ts @@ -327,49 +327,63 @@ export class EmployeePositionController extends Controller { break; case "positionLevel": - if (!isNaN(Number(keyword))) { - let findEmpLevels; - if (Number(keyword) === 0) { - findEmpLevels = await this.employeePosLevelRepository.find(); - } else { - findEmpLevels = await this.employeePosLevelRepository.find({ - where: { posLevelName: Number(keyword) }, - }); - } - findData = await this.employeePosDictRepository.find({ - where: { posLevelId: In(findEmpLevels.map((x) => x.id)) }, - relations: ["posType", "posLevel"], - order: { - posDictName: "ASC", - createdAt: "DESC", - posType: { - posTypeRank: "ASC", - createdAt: "DESC", - }, - posLevel: { - posLevelName: "ASC", - createdAt: "DESC", - }, - }, - }); - } else { - //กรณีเลือกค้นหาจาก"ระดับชั้นงาน" แต่กรอกไม่ใช่ number ให้ปล่อยมาหมดเลย - findData = await this.employeePosDictRepository.find({ - relations: ["posType", "posLevel"], - order: { - posDictName: "ASC", - createdAt: "DESC", - posType: { - posTypeRank: "ASC", - createdAt: "DESC", - }, - posLevel: { - posLevelName: "ASC", - createdAt: "DESC", - }, - }, - }); - } + // if (!isNaN(Number(keyword))) { + // console.log(">>>>>>>>", keyword); + // let findEmpLevels; + // if (Number(keyword) === 0) { + // findEmpLevels = await this.employeePosLevelRepository.find(); + // } else { + // findEmpLevels = await this.employeePosLevelRepository.find({ + // where: { posLevelName: Number(keyword) }, + // }); + // } + // findData = await this.employeePosDictRepository.find({ + // where: { posLevelId: In(findEmpLevels.map((x) => x.id)) }, + // relations: ["posType", "posLevel"], + // order: { + // posDictName: "ASC", + // createdAt: "DESC", + // posType: { + // posTypeRank: "ASC", + // createdAt: "DESC", + // }, + // posLevel: { + // posLevelName: "ASC", + // createdAt: "DESC", + // }, + // }, + // }); + // } else { + // //กรณีเลือกค้นหาจาก"ระดับชั้นงาน" แต่กรอกไม่ใช่ number ให้ปล่อยมาหมดเลย + // findData = await this.employeePosDictRepository.find({ + // relations: ["posType", "posLevel"], + // order: { + // posDictName: "ASC", + // createdAt: "DESC", + // posType: { + // posTypeRank: "ASC", + // createdAt: "DESC", + // }, + // posLevel: { + // posLevelName: "ASC", + // createdAt: "DESC", + // }, + // }, + // }); + // } + findData = await this.employeePosDictRepository + .createQueryBuilder("posDict") + .leftJoinAndSelect("posDict.posType", "posType") + .leftJoinAndSelect("posDict.posLevel", "posLevel") + .where( keyword + ? "CONCAT(posType.posTypeShortName, ' ', posLevel.posLevelName) LIKE :keyword":"1=1", {keyword: `%${keyword}%`}) + .orderBy("posDict.posDictName", "ASC") + .addOrderBy("posDict.createdAt", "DESC") + .addOrderBy("posType.posTypeRank", "ASC") + .addOrderBy("posType.createdAt", "DESC") + .addOrderBy("posLevel.posLevelName", "ASC") + .addOrderBy("posLevel.createdAt", "DESC") + .getMany(); break; default: