ค้นหาทะเบียนประวัติ

This commit is contained in:
Kittapath 2024-02-16 12:07:37 +07:00
parent 14bc29b675
commit 5fc7aa0938
5 changed files with 207 additions and 55 deletions

View file

@ -176,9 +176,9 @@ export class PositionController extends Controller {
where: { posDictName: Like(`%${keyword}%`) },
relations: ["posType", "posLevel", "posExecutive"],
});
if (!findPosDict) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
}
// if (!findPosDict) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
// }
break;
case "positionField":
@ -186,9 +186,9 @@ export class PositionController extends Controller {
where: { posDictField: Like(`%${keyword}%`) },
relations: ["posType", "posLevel", "posExecutive"],
});
if (!findPosDict) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
}
// if (!findPosDict) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
// }
break;
case "positionType":
@ -229,9 +229,9 @@ export class PositionController extends Controller {
where: { posDictExecutiveField: Like(`%${keyword}%`) },
relations: ["posType", "posLevel", "posExecutive"],
});
if (!findPosDict) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
}
// if (!findPosDict) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
// }
break;
case "positionArea":
@ -239,18 +239,18 @@ export class PositionController extends Controller {
where: { posDictArea: Like(`%${keyword}%`) },
relations: ["posType", "posLevel", "posExecutive"],
});
if (!findPosDict) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
}
// if (!findPosDict) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
// }
break;
default:
findPosDict = await this.posDictRepository.find({
relations: ["posType", "posLevel", "posExecutive"],
});
if (!findPosDict) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
// if (!findPosDict) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
// }
break;
}
@ -812,37 +812,33 @@ export class PositionController extends Controller {
// });
const [posMaster, total] = await AppDataSource.getRepository(PosMaster)
.createQueryBuilder('posMaster')
.leftJoinAndSelect('posMaster.orgRoot', 'orgRoot')
.leftJoinAndSelect('posMaster.orgChild1', 'orgChild1')
.leftJoinAndSelect('posMaster.orgChild2', 'orgChild2')
.leftJoinAndSelect('posMaster.orgChild3', 'orgChild3')
.leftJoinAndSelect('posMaster.orgChild4', 'orgChild4')
.leftJoinAndSelect('posMaster.current_holder', 'current_holder')
.leftJoinAndSelect('posMaster.next_holder', 'next_holder')
.where(conditions)
.orWhere(
new Brackets((qb) => {
qb.where(
body.keyword != null && body.keyword != ""
? "CONCAT(current_holder.prefix, current_holder.firstName, current_holder.lastName) LIKE :keyword OR :keyword LIKE current_holder.prefix OR :keyword LIKE current_holder.firstName OR :keyword LIKE current_holder.lastName "
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.andWhere(
checkChildConditions
)
.andWhere(
typeCondition
);
})
)
.orderBy('posMaster.posMasterOrder', 'ASC')
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
.getManyAndCount();
.createQueryBuilder("posMaster")
.leftJoinAndSelect("posMaster.orgRoot", "orgRoot")
.leftJoinAndSelect("posMaster.orgChild1", "orgChild1")
.leftJoinAndSelect("posMaster.orgChild2", "orgChild2")
.leftJoinAndSelect("posMaster.orgChild3", "orgChild3")
.leftJoinAndSelect("posMaster.orgChild4", "orgChild4")
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
.leftJoinAndSelect("posMaster.next_holder", "next_holder")
.where(conditions)
.orWhere(
new Brackets((qb) => {
qb.where(
body.keyword != null && body.keyword != ""
? "CONCAT(current_holder.prefix, current_holder.firstName, current_holder.lastName) LIKE :keyword OR :keyword LIKE current_holder.prefix OR :keyword LIKE current_holder.firstName OR :keyword LIKE current_holder.lastName "
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.andWhere(checkChildConditions)
.andWhere(typeCondition);
}),
)
.orderBy("posMaster.posMasterOrder", "ASC")
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
.getManyAndCount();
const formattedData = await Promise.all(
posMaster.map(async (posMaster) => {
@ -855,14 +851,13 @@ export class PositionController extends Controller {
let profile: any;
const chkRevision = await this.orgRevisionRepository.findOne({
where: { id: posMaster.orgRevisionId }
})
if(chkRevision?.orgRevisionIsCurrent && !chkRevision?.orgRevisionIsDraft){
where: { id: posMaster.orgRevisionId },
});
if (chkRevision?.orgRevisionIsCurrent && !chkRevision?.orgRevisionIsDraft) {
profile = await this.profileRepository.findOne({
where: { id: String(posMaster.current_holderId) },
});
}
else if(!chkRevision?.orgRevisionIsCurrent && chkRevision?.orgRevisionIsDraft){
} else if (!chkRevision?.orgRevisionIsCurrent && chkRevision?.orgRevisionIsDraft) {
profile = await this.profileRepository.findOne({
where: { id: String(posMaster.next_holderId) },
});
@ -940,10 +935,8 @@ export class PositionController extends Controller {
: `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`,
orgShortname: shortName,
isSit: posMaster.isSit,
profilePosition:
profile == null || profile.position == null ? null : profile.position,
profilePostype:
type == null || type.posTypeName == null ? null : type.posTypeName,
profilePosition: profile == null || profile.position == null ? null : profile.position,
profilePostype: type == null || type.posTypeName == null ? null : type.posTypeName,
profilePoslevel:
level == null || level.posLevelName == null ? null : level.posLevelName,
positions: positions.map((position) => ({