ค้นหารายชื่อถ้าไม่ส่ง system มาให้ default ตามทะเบียนประวัติ #1689
This commit is contained in:
parent
0f89aa4a92
commit
900fb8deb5
3 changed files with 342 additions and 528 deletions
|
|
@ -2174,97 +2174,108 @@ export class ProfileEmployeeTempController extends Controller {
|
|||
*/
|
||||
@Post("search-personal")
|
||||
async getProfileBySearchKeyword(
|
||||
@Request() request: RequestWithUser,
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Body()
|
||||
body: {
|
||||
fieldName: string;
|
||||
keyword?: string;
|
||||
system?: string;
|
||||
},
|
||||
) {
|
||||
let findProfile: any;
|
||||
let total: any;
|
||||
const skip = (page - 1) * pageSize;
|
||||
const take = pageSize;
|
||||
switch (body.fieldName) {
|
||||
case "citizenId":
|
||||
[findProfile, total] = await this.profileRepo.findAndCount({
|
||||
where: { citizenId: Like(`%${body.keyword}%`) },
|
||||
relations: [
|
||||
"posType",
|
||||
"posLevel",
|
||||
"current_holders",
|
||||
"current_holders.orgRoot",
|
||||
"current_holders.orgChild1",
|
||||
"current_holders.orgChild2",
|
||||
"current_holders.orgChild3",
|
||||
"current_holders.orgChild4",
|
||||
],
|
||||
skip,
|
||||
take,
|
||||
});
|
||||
break;
|
||||
|
||||
case "firstname":
|
||||
[findProfile, total] = await this.profileRepo.findAndCount({
|
||||
where: { firstName: Like(`%${body.keyword}%`) },
|
||||
relations: [
|
||||
"posType",
|
||||
"posLevel",
|
||||
"current_holders",
|
||||
"current_holders.orgRoot",
|
||||
"current_holders.orgChild1",
|
||||
"current_holders.orgChild2",
|
||||
"current_holders.orgChild3",
|
||||
"current_holders.orgChild4",
|
||||
],
|
||||
skip,
|
||||
take,
|
||||
});
|
||||
break;
|
||||
|
||||
case "lastname":
|
||||
[findProfile, total] = await this.profileRepo.findAndCount({
|
||||
where: { lastName: Like(`%${body.keyword}%`) },
|
||||
relations: [
|
||||
"posType",
|
||||
"posLevel",
|
||||
"current_holders",
|
||||
"current_holders.orgRoot",
|
||||
"current_holders.orgChild1",
|
||||
"current_holders.orgChild2",
|
||||
"current_holders.orgChild3",
|
||||
"current_holders.orgChild4",
|
||||
],
|
||||
skip,
|
||||
take,
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
[findProfile, total] = await this.profileRepo.findAndCount({
|
||||
relations: [
|
||||
"posType",
|
||||
"posLevel",
|
||||
"current_holders",
|
||||
"current_holders.orgRoot",
|
||||
"current_holders.orgChild1",
|
||||
"current_holders.orgChild2",
|
||||
"current_holders.orgChild3",
|
||||
"current_holders.orgChild4",
|
||||
],
|
||||
skip,
|
||||
take,
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
const findRevision = await this.orgRevisionRepo.findOne({
|
||||
where: { orgRevisionIsCurrent: true },
|
||||
});
|
||||
// ค้นหารายชื่อถ้าไม่ส่ง system มาให้ default ตามทะเบียนประวัติ
|
||||
let _system:string ="SYS_REGISTRY_TEMP";
|
||||
if(body.system)
|
||||
_system = body.system;
|
||||
let _data = await new permission().PermissionOrgList(request, _system);
|
||||
const findRevision = await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true } });
|
||||
if (!findRevision) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
|
||||
}
|
||||
let queryLike = "1=1"
|
||||
switch (body.fieldName) {
|
||||
case "citizenId":
|
||||
queryLike = "profile.citizenId LIKE :keyword";
|
||||
break;
|
||||
|
||||
case "firstname":
|
||||
queryLike = "profile.firstName LIKE :keyword";
|
||||
break;
|
||||
|
||||
case "lastname":
|
||||
queryLike = "profile.lastName LIKE :keyword";
|
||||
break;
|
||||
|
||||
case "fullName":
|
||||
queryLike = "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword";
|
||||
break;
|
||||
|
||||
default:
|
||||
queryLike = "1=1"
|
||||
break;
|
||||
}
|
||||
|
||||
const [findProfile, total] = await this.profileRepo
|
||||
.createQueryBuilder("profile")
|
||||
.leftJoinAndSelect("profile.posType", "posType")
|
||||
.leftJoinAndSelect("profile.posLevel", "posLevel")
|
||||
.leftJoinAndSelect("profile.current_holders", "current_holders")
|
||||
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
|
||||
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
|
||||
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
|
||||
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
|
||||
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
|
||||
.where("current_holders.orgRevision = :revisionId", { revisionId: findRevision?.id })
|
||||
.andWhere("profile.employeeClass = :employeeClass", { employeeClass: "TEMP" })
|
||||
.andWhere(
|
||||
_data.root != undefined && _data.root != null
|
||||
? _data.root[0] != null
|
||||
? `current_holders.orgRootId IN (:...root)`
|
||||
: `current_holders.orgRootId is null`
|
||||
: "1=1",
|
||||
{ root: _data.root },
|
||||
)
|
||||
.andWhere(
|
||||
_data.child1 != undefined && _data.child1 != null
|
||||
? _data.child1[0] != null
|
||||
? `current_holders.orgChild1Id IN (:...child1)`
|
||||
: `current_holders.orgChild1Id is null`
|
||||
: "1=1",
|
||||
{ child1: _data.child1 },
|
||||
)
|
||||
.andWhere(
|
||||
_data.child2 != undefined && _data.child2 != null
|
||||
? _data.child2[0] != null
|
||||
? `current_holders.orgChild2Id IN (:...child2)`
|
||||
: `current_holders.orgChild2Id is null`
|
||||
: "1=1",
|
||||
{ child2: _data.child2 },
|
||||
)
|
||||
.andWhere(
|
||||
_data.child3 != undefined && _data.child3 != null
|
||||
? _data.child3[0] != null
|
||||
? `current_holders.orgChild3Id IN (:...child3)`
|
||||
: `current_holders.orgChild3Id is null`
|
||||
: "1=1",
|
||||
{ child3: _data.child3 },
|
||||
)
|
||||
.andWhere(
|
||||
_data.child4 != undefined && _data.child4 != null
|
||||
? _data.child4[0] != null
|
||||
? `current_holders.orgChild4Id IN (:...child4)`
|
||||
: `current_holders.orgChild4Id is null`
|
||||
: "1=1",
|
||||
{ child4: _data.child4 },
|
||||
)
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.orWhere(body.keyword ? queryLike : "1=1", { keyword: `%${body.keyword}%` });
|
||||
}),
|
||||
)
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
const mapDataProfile = await Promise.all(
|
||||
findProfile.map(async (item: ProfileEmployee) => {
|
||||
|
|
@ -2369,7 +2380,10 @@ export class ProfileEmployeeTempController extends Controller {
|
|||
posTypeId: item.posTypeId,
|
||||
posTypeName: item.posType?.posTypeName,
|
||||
posLevelId: item.posLevelId,
|
||||
posLevelName: item.posLevel?.posLevelName,
|
||||
posLevelName:
|
||||
item.posLevel == null && item.posType == null
|
||||
? null
|
||||
: `${item.posType?.posTypeShortName} ${item.posLevel?.posLevelName}`,
|
||||
educationDegree:
|
||||
latestProfileEducation != null && latestProfileEducation.educationLevel != null
|
||||
? latestProfileEducation.educationLevel
|
||||
|
|
@ -3972,7 +3986,10 @@ export class ProfileEmployeeTempController extends Controller {
|
|||
posTypeId: item.posTypeId,
|
||||
posTypeName: item.posType?.posTypeName,
|
||||
posLevelId: item.posLevelId,
|
||||
posLevelName: item.posLevel?.posLevelName,
|
||||
posLevelName:
|
||||
item.posLevel == null && item.posType == null
|
||||
? null
|
||||
: `${item.posType?.posTypeShortName} ${item.posLevel?.posLevelName}`,
|
||||
educationDegree:
|
||||
latestProfileEducation != null && latestProfileEducation.educationLevel != null
|
||||
? latestProfileEducation.educationLevel
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue