This commit is contained in:
AdisakKanthawilang 2025-07-29 10:54:53 +07:00
parent e24e5de129
commit 0aca69b371

View file

@ -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: