fix registry retire
This commit is contained in:
parent
4994c829b5
commit
b76895012c
2 changed files with 516 additions and 474 deletions
|
|
@ -87,6 +87,8 @@ import { ProfileAssistance } from "../entities/ProfileAssistance";
|
|||
import { CommandRecive } from "../entities/CommandRecive";
|
||||
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
||||
import { getTopDegrees } from "../services/PositionService";
|
||||
import { ProfileLeaveService } from "../services/ProfileLeaveService";
|
||||
|
||||
@Route("api/v1/org/profile")
|
||||
@Tags("Profile")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -141,6 +143,9 @@ export class ProfileController extends Controller {
|
|||
private profileAssistanceRepository = AppDataSource.getRepository(ProfileAssistance);
|
||||
private commandReciveRepository = AppDataSource.getRepository(CommandRecive);
|
||||
|
||||
// Services
|
||||
private profileLeaveService = new ProfileLeaveService();
|
||||
|
||||
/**
|
||||
* report ประวัติแบบย่อ ข้าราชการ
|
||||
*
|
||||
|
|
@ -2725,19 +2730,19 @@ export class ProfileController extends Controller {
|
|||
},
|
||||
);
|
||||
}),
|
||||
)
|
||||
);
|
||||
|
||||
if (body.sortBy) {
|
||||
query = query.orderBy(
|
||||
`viewDirectorActing.${body.sortBy}`,
|
||||
body.descending ? "DESC" : "ASC"
|
||||
body.descending ? "DESC" : "ASC",
|
||||
);
|
||||
}
|
||||
|
||||
const [lists, total] = await query
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
.take(body.pageSize)
|
||||
.getManyAndCount();
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
.take(body.pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
return new HttpSuccess({ data: lists, total });
|
||||
} else {
|
||||
|
|
@ -2827,13 +2832,10 @@ export class ProfileController extends Controller {
|
|||
},
|
||||
);
|
||||
}),
|
||||
)
|
||||
);
|
||||
|
||||
if (body.sortBy) {
|
||||
query = query.orderBy(
|
||||
`viewDirector.${body.sortBy}`,
|
||||
body.descending ? "DESC" : "ASC"
|
||||
);
|
||||
query = query.orderBy(`viewDirector.${body.sortBy}`, body.descending ? "DESC" : "ASC");
|
||||
}
|
||||
|
||||
const [lists, total] = await query
|
||||
|
|
@ -5706,35 +5708,18 @@ export class ProfileController extends Controller {
|
|||
result: {
|
||||
data: [
|
||||
{
|
||||
id: "ecb0b34c-037e-41f2-b95e-7e19f88b42ae",
|
||||
createdAt: "2024-03-24T12:39:12.105Z",
|
||||
createdUserId: "00000000-0000-0000-0000-000000000000",
|
||||
lastUpdatedAt: "2024-03-24T12:41:43.164Z",
|
||||
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
|
||||
createdFullName: "string",
|
||||
lastUpdateFullName: "string",
|
||||
rank: null,
|
||||
prefix: null,
|
||||
firstName: "Methapon",
|
||||
lastName: "Metanipat",
|
||||
citizenId: null,
|
||||
position: null,
|
||||
posLevelId: null,
|
||||
posTypeId: null,
|
||||
email: null,
|
||||
phone: null,
|
||||
keycloak: null,
|
||||
page: 1,
|
||||
pageSize: 12,
|
||||
posLevel: "ปฏิบัติงาน",
|
||||
posType: "ทั่วไป",
|
||||
isProbation: false,
|
||||
dateRetire: null,
|
||||
birthDate: null,
|
||||
ethnicity: null,
|
||||
telephoneNumber: null,
|
||||
gender: null,
|
||||
relationship: null,
|
||||
bloodGroup: null,
|
||||
posLevel: null,
|
||||
posType: null,
|
||||
org: null,
|
||||
isRetire: true,
|
||||
node: 0,
|
||||
nodeId: "8349b6b6-d005-4eb7-9960-ceb5b96e1962",
|
||||
isAll: true,
|
||||
sortBy: "profile.dateAppoint",
|
||||
sort: "DESC",
|
||||
retireType: "RETIRE",
|
||||
},
|
||||
],
|
||||
total: 1,
|
||||
|
|
@ -5749,9 +5734,7 @@ export class ProfileController extends Controller {
|
|||
@Query() searchKeyword: string = "",
|
||||
@Query() posType?: string,
|
||||
@Query() posLevel?: string,
|
||||
@Query() yearLeave?: number,
|
||||
@Query() isProbation?: boolean,
|
||||
// @Query() isRetire?: boolean,
|
||||
@Query() node?: number,
|
||||
@Query() nodeId?: string,
|
||||
@Query() isAll?: boolean,
|
||||
|
|
@ -5759,325 +5742,236 @@ export class ProfileController extends Controller {
|
|||
@Query() sortBy: string = "current_holders.posMasterNo",
|
||||
@Query() sort: "ASC" | "DESC" = "ASC",
|
||||
) {
|
||||
let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER");
|
||||
let queryLike =
|
||||
"CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword";
|
||||
if (searchField == "citizenId") {
|
||||
queryLike = "profile.citizenId LIKE :keyword";
|
||||
} else if (searchField == "position") {
|
||||
queryLike = "profile.position LIKE :keyword";
|
||||
}
|
||||
const { data, total } = await this.profileLeaveService.getLeaveOfficer(request, {
|
||||
page,
|
||||
pageSize,
|
||||
searchField,
|
||||
searchKeyword,
|
||||
posType,
|
||||
posLevel,
|
||||
isProbation,
|
||||
node,
|
||||
nodeId,
|
||||
isAll,
|
||||
retireType,
|
||||
sortBy,
|
||||
sort,
|
||||
});
|
||||
|
||||
// let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER");
|
||||
// let queryLike =
|
||||
// "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword";
|
||||
// if (searchField == "citizenId") {
|
||||
// queryLike = "profile.citizenId LIKE :keyword";
|
||||
// } else if (searchField == "position") {
|
||||
// queryLike = "profile.position LIKE :keyword";
|
||||
// }
|
||||
// else if (searchField == "posNo") {
|
||||
// queryLike = `
|
||||
// CASE
|
||||
// WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, current_holders.posMasterNo)
|
||||
// WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, current_holders.posMasterNo)
|
||||
// WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT(orgChild2.orgChild2ShortName, current_holders.posMasterNo)
|
||||
// WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo)
|
||||
// ELSE CONCAT(orgRoot.orgRootShortName, current_holders.posMasterNo)
|
||||
// END LIKE :keyword
|
||||
// `;
|
||||
// }
|
||||
else if (searchField == "posNo") {
|
||||
queryLike = `
|
||||
CONCAT(profileSalary.posNoAbb, profileSalary.posNo) LIKE :keyword
|
||||
OR CONCAT(profileSalary.posNoAbb, " ", profileSalary.posNo) LIKE :keyword
|
||||
OR profileSalary.posNo LIKE :keyword
|
||||
`;
|
||||
}
|
||||
let nodeCondition = "1=1";
|
||||
let nodeAll = "";
|
||||
let orgRoot = null;
|
||||
let orgChild1 = null;
|
||||
let orgChild2 = null;
|
||||
let orgChild3 = null;
|
||||
let orgChild4 = null;
|
||||
// queryLike = `
|
||||
// CONCAT(profileSalary.posNoAbb, profileSalary.posNo) LIKE :keyword
|
||||
// OR CONCAT(profileSalary.posNoAbb, " ", profileSalary.posNo) LIKE :keyword
|
||||
// OR profileSalary.posNo LIKE :keyword
|
||||
// `;
|
||||
// }
|
||||
// let nodeCondition = "1=1";
|
||||
// let nodeAll = "";
|
||||
// let orgRoot = null;
|
||||
// let orgChild1 = null;
|
||||
// let orgChild2 = null;
|
||||
// let orgChild3 = null;
|
||||
// let orgChild4 = null;
|
||||
|
||||
let pmsCondition = "1=1";
|
||||
let orgRootPms = null;
|
||||
let orgChild1Pms = null;
|
||||
let orgChild2Pms = null;
|
||||
let orgChild3Pms = null;
|
||||
let orgChild4Pms = null;
|
||||
// let pmsCondition = "1=1";
|
||||
// let orgRootPms = null;
|
||||
// let orgChild1Pms = null;
|
||||
// let orgChild2Pms = null;
|
||||
// let orgChild3Pms = null;
|
||||
// let orgChild4Pms = null;
|
||||
|
||||
if (node === 0 && nodeId) {
|
||||
orgRoot = await this.orgRootRepo.findOne({ where: { id: nodeId } });
|
||||
if (orgRoot) {
|
||||
nodeCondition = "profileSalary.orgRoot = :orgRoot";
|
||||
}
|
||||
if (isAll == false) nodeAll = " AND profileSalary.orgChild1 IS NULL";
|
||||
} else if (node === 1 && nodeId) {
|
||||
orgChild1 = await this.orgChild1Repo.findOne({ where: { id: nodeId } });
|
||||
if (orgChild1) {
|
||||
nodeCondition = "profileSalary.orgChild1 = :orgChild1";
|
||||
}
|
||||
if (isAll == false) nodeAll = " AND profileSalary.orgChild2 IS NULL";
|
||||
} else if (node === 2 && nodeId) {
|
||||
orgChild2 = await this.orgChild2Repo.findOne({ where: { id: nodeId } });
|
||||
if (orgChild2) {
|
||||
nodeCondition = "profileSalary.orgChild2 = :orgChild2";
|
||||
}
|
||||
if (isAll == false) nodeAll = " AND profileSalary.orgChild3 IS NULL";
|
||||
} else if (node === 3 && nodeId) {
|
||||
orgChild3 = await this.orgChild3Repo.findOne({ where: { id: nodeId } });
|
||||
if (orgChild3) {
|
||||
nodeCondition = "profileSalary.orgChild3 = :orgChild3";
|
||||
}
|
||||
if (isAll == false) nodeAll = " AND profileSalary.orgChild4 IS NULL";
|
||||
} else if (node === 4 && nodeId) {
|
||||
orgChild4 = await this.orgChild4Repo.findOne({ where: { id: nodeId } });
|
||||
if (orgChild4) {
|
||||
nodeCondition = "profileSalary.orgChild4 = :orgChild4";
|
||||
}
|
||||
}
|
||||
nodeCondition = nodeCondition + nodeAll;
|
||||
// if (node === 0 && nodeId) {
|
||||
// orgRoot = await this.orgRootRepo.findOne({ where: { id: nodeId } });
|
||||
// if (orgRoot) {
|
||||
// nodeCondition = "profileSalary.orgRoot = :orgRoot";
|
||||
// }
|
||||
// if (isAll == false) nodeAll = " AND profileSalary.orgChild1 IS NULL";
|
||||
// } else if (node === 1 && nodeId) {
|
||||
// orgChild1 = await this.orgChild1Repo.findOne({ where: { id: nodeId } });
|
||||
// if (orgChild1) {
|
||||
// nodeCondition = "profileSalary.orgChild1 = :orgChild1";
|
||||
// }
|
||||
// if (isAll == false) nodeAll = " AND profileSalary.orgChild2 IS NULL";
|
||||
// } else if (node === 2 && nodeId) {
|
||||
// orgChild2 = await this.orgChild2Repo.findOne({ where: { id: nodeId } });
|
||||
// if (orgChild2) {
|
||||
// nodeCondition = "profileSalary.orgChild2 = :orgChild2";
|
||||
// }
|
||||
// if (isAll == false) nodeAll = " AND profileSalary.orgChild3 IS NULL";
|
||||
// } else if (node === 3 && nodeId) {
|
||||
// orgChild3 = await this.orgChild3Repo.findOne({ where: { id: nodeId } });
|
||||
// if (orgChild3) {
|
||||
// nodeCondition = "profileSalary.orgChild3 = :orgChild3";
|
||||
// }
|
||||
// if (isAll == false) nodeAll = " AND profileSalary.orgChild4 IS NULL";
|
||||
// } else if (node === 4 && nodeId) {
|
||||
// orgChild4 = await this.orgChild4Repo.findOne({ where: { id: nodeId } });
|
||||
// if (orgChild4) {
|
||||
// nodeCondition = "profileSalary.orgChild4 = :orgChild4";
|
||||
// }
|
||||
// }
|
||||
// nodeCondition = nodeCondition + nodeAll;
|
||||
|
||||
if (_data.root) {
|
||||
orgRootPms = await this.orgRootRepo.findOne({ where: { id: _data.root } });
|
||||
if (orgRootPms) {
|
||||
pmsCondition = "profileSalary.orgRoot = :orgRootPms";
|
||||
}
|
||||
if (isAll == false) nodeAll = " AND profileSalary.orgChild1 IS NULL";
|
||||
} else if (_data.child1) {
|
||||
orgChild1Pms = await this.orgChild1Repo.findOne({ where: { id: _data.child1 } });
|
||||
if (orgChild1Pms) {
|
||||
pmsCondition = "profileSalary.orgChild1 = :orgChild1Pms";
|
||||
}
|
||||
if (isAll == false) nodeAll = " AND profileSalary.orgChild2 IS NULL";
|
||||
} else if (_data.child2) {
|
||||
orgChild2Pms = await this.orgChild2Repo.findOne({ where: { id: _data.child2 } });
|
||||
if (orgChild2Pms) {
|
||||
pmsCondition = "profileSalary.orgChild2 = :orgChild2Pms";
|
||||
}
|
||||
if (isAll == false) nodeAll = " AND profileSalary.orgChild3 IS NULL";
|
||||
} else if (_data.child3) {
|
||||
orgChild3Pms = await this.orgChild3Repo.findOne({ where: { id: _data.child3 } });
|
||||
if (orgChild3Pms) {
|
||||
pmsCondition = "profileSalary.orgChild3 = :orgChild3Pms";
|
||||
}
|
||||
if (isAll == false) nodeAll = " AND profileSalary.orgChild4 IS NULL";
|
||||
} else if (_data.child4) {
|
||||
orgChild4Pms = await this.orgChild4Repo.findOne({ where: { id: _data.child4 } });
|
||||
if (orgChild4Pms) {
|
||||
pmsCondition = "profileSalary.orgChild4 = :orgChild4Pms";
|
||||
}
|
||||
}
|
||||
pmsCondition = pmsCondition + nodeAll;
|
||||
// if (_data.root) {
|
||||
// orgRootPms = await this.orgRootRepo.findOne({ where: { id: _data.root } });
|
||||
// if (orgRootPms) {
|
||||
// pmsCondition = "profileSalary.orgRoot = :orgRootPms";
|
||||
// }
|
||||
// if (isAll == false) nodeAll = " AND profileSalary.orgChild1 IS NULL";
|
||||
// } else if (_data.child1) {
|
||||
// orgChild1Pms = await this.orgChild1Repo.findOne({ where: { id: _data.child1 } });
|
||||
// if (orgChild1Pms) {
|
||||
// pmsCondition = "profileSalary.orgChild1 = :orgChild1Pms";
|
||||
// }
|
||||
// if (isAll == false) nodeAll = " AND profileSalary.orgChild2 IS NULL";
|
||||
// } else if (_data.child2) {
|
||||
// orgChild2Pms = await this.orgChild2Repo.findOne({ where: { id: _data.child2 } });
|
||||
// if (orgChild2Pms) {
|
||||
// pmsCondition = "profileSalary.orgChild2 = :orgChild2Pms";
|
||||
// }
|
||||
// if (isAll == false) nodeAll = " AND profileSalary.orgChild3 IS NULL";
|
||||
// } else if (_data.child3) {
|
||||
// orgChild3Pms = await this.orgChild3Repo.findOne({ where: { id: _data.child3 } });
|
||||
// if (orgChild3Pms) {
|
||||
// pmsCondition = "profileSalary.orgChild3 = :orgChild3Pms";
|
||||
// }
|
||||
// if (isAll == false) nodeAll = " AND profileSalary.orgChild4 IS NULL";
|
||||
// } else if (_data.child4) {
|
||||
// orgChild4Pms = await this.orgChild4Repo.findOne({ where: { id: _data.child4 } });
|
||||
// if (orgChild4Pms) {
|
||||
// pmsCondition = "profileSalary.orgChild4 = :orgChild4Pms";
|
||||
// }
|
||||
// }
|
||||
// pmsCondition = pmsCondition + nodeAll;
|
||||
|
||||
// const findRevision = await this.orgRevisionRepo.findOne({
|
||||
// where: { orgRevisionIsCurrent: true },
|
||||
// });
|
||||
// if (!findRevision) {
|
||||
// throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
|
||||
// }
|
||||
const [record, total] = await this.profileRepo
|
||||
.createQueryBuilder("profile")
|
||||
.leftJoinAndSelect("profile.posLevel", "posLevel")
|
||||
.leftJoinAndSelect("profile.posType", "posType")
|
||||
.leftJoinAndSelect("profile.profileSalary", "profileSalary")
|
||||
// .leftJoinAndSelect("profile.current_holders", "current_holders")
|
||||
// .leftJoinAndSelect("current_holders.positions", "positions")
|
||||
// .leftJoinAndSelect("positions.posExecutive", "posExecutive")
|
||||
.where(
|
||||
new Brackets((qb) => {
|
||||
qb.where("profile.isLeave = :isLeave", { isLeave: true }).orWhere(
|
||||
"profile.isRetirement = :isRetirement",
|
||||
{ isRetirement: true },
|
||||
);
|
||||
}),
|
||||
)
|
||||
// .andWhere("profile.leaveCommandId Is NOT NULL")
|
||||
.andWhere(
|
||||
"profileSalary.order = (SELECT MAX(ps.order) FROM profileSalary ps WHERE ps.profileId = profile.id and ps.positionName != 'เกษียณอายุราชการ')",
|
||||
)
|
||||
// const [record, total] = await this.profileRepo
|
||||
// .createQueryBuilder("profile")
|
||||
// .leftJoinAndSelect("profile.posLevel", "posLevel")
|
||||
// .leftJoinAndSelect("profile.posType", "posType")
|
||||
// .leftJoinAndSelect("profile.profileSalary", "profileSalary")
|
||||
// .where(
|
||||
// new Brackets((qb) => {
|
||||
// qb.where("profile.isLeave = :isLeave", { isLeave: true }).orWhere(
|
||||
// "profile.isRetirement = :isRetirement",
|
||||
// { isRetirement: true },
|
||||
// );
|
||||
// }),
|
||||
// )
|
||||
// .andWhere(
|
||||
// "profileSalary.order = (SELECT MAX(ps.order) FROM profileSalary ps WHERE ps.profileId = profile.id and ps.positionName != 'เกษียณอายุราชการ')",
|
||||
// )
|
||||
|
||||
.andWhere(
|
||||
posType != undefined && posType != null && posType != ""
|
||||
? "posType.posTypeName LIKE :keyword1"
|
||||
: "1=1",
|
||||
{
|
||||
keyword1: `${posType}`,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
posLevel != undefined && posLevel != null && posLevel != ""
|
||||
? "posLevel.posLevelName LIKE :keyword2"
|
||||
: "1=1",
|
||||
{
|
||||
keyword2: `${posLevel}`,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
isProbation != undefined && isProbation != null
|
||||
? `profile.isProbation = ${isProbation}`
|
||||
: "1=1",
|
||||
)
|
||||
.andWhere(
|
||||
retireType != undefined && retireType != null ? `profile.leaveType = :retireType` : "1=1",
|
||||
{ retireType: retireType },
|
||||
)
|
||||
.andWhere(pmsCondition, {
|
||||
orgRootPms: orgRootPms ? orgRootPms.orgRootName : "",
|
||||
orgChild1Pms: orgChild1Pms ? orgChild1Pms.orgChild1Name : "",
|
||||
orgChild2Pms: orgChild2Pms ? orgChild2Pms.orgChild2Name : "",
|
||||
orgChild3Pms: orgChild3Pms ? orgChild3Pms.orgChild3Name : "",
|
||||
orgChild4Pms: orgChild4Pms ? orgChild4Pms.orgChild4Name : "",
|
||||
})
|
||||
.andWhere(nodeCondition, {
|
||||
orgRoot: orgRoot ? orgRoot.orgRootName : "",
|
||||
orgChild1: orgChild1 ? orgChild1.orgChild1Name : "",
|
||||
orgChild2: orgChild2 ? orgChild2.orgChild2Name : "",
|
||||
orgChild3: orgChild3 ? orgChild3.orgChild3Name : "",
|
||||
orgChild4: orgChild4 ? orgChild4.orgChild4Name : "",
|
||||
})
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.orWhere(
|
||||
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
|
||||
? queryLike
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${searchKeyword}%`,
|
||||
},
|
||||
);
|
||||
}),
|
||||
)
|
||||
// .orderBy("current_holders.posMasterNo", "ASC")
|
||||
// .orderBy(`${sortBy}`, sort)
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
// .andWhere(
|
||||
// posType != undefined && posType != null && posType != ""
|
||||
// ? "posType.posTypeName LIKE :keyword1"
|
||||
// : "1=1",
|
||||
// {
|
||||
// keyword1: `${posType}`,
|
||||
// },
|
||||
// )
|
||||
// .andWhere(
|
||||
// posLevel != undefined && posLevel != null && posLevel != ""
|
||||
// ? "posLevel.posLevelName LIKE :keyword2"
|
||||
// : "1=1",
|
||||
// {
|
||||
// keyword2: `${posLevel}`,
|
||||
// },
|
||||
// )
|
||||
// .andWhere(
|
||||
// isProbation != undefined && isProbation != null
|
||||
// ? `profile.isProbation = ${isProbation}`
|
||||
// : "1=1",
|
||||
// )
|
||||
// .andWhere(
|
||||
// retireType != undefined && retireType != null ? `profile.leaveType = :retireType` : "1=1",
|
||||
// { retireType: retireType },
|
||||
// )
|
||||
// .andWhere(pmsCondition, {
|
||||
// orgRootPms: orgRootPms ? orgRootPms.orgRootName : "",
|
||||
// orgChild1Pms: orgChild1Pms ? orgChild1Pms.orgChild1Name : "",
|
||||
// orgChild2Pms: orgChild2Pms ? orgChild2Pms.orgChild2Name : "",
|
||||
// orgChild3Pms: orgChild3Pms ? orgChild3Pms.orgChild3Name : "",
|
||||
// orgChild4Pms: orgChild4Pms ? orgChild4Pms.orgChild4Name : "",
|
||||
// })
|
||||
// .andWhere(nodeCondition, {
|
||||
// orgRoot: orgRoot ? orgRoot.orgRootName : "",
|
||||
// orgChild1: orgChild1 ? orgChild1.orgChild1Name : "",
|
||||
// orgChild2: orgChild2 ? orgChild2.orgChild2Name : "",
|
||||
// orgChild3: orgChild3 ? orgChild3.orgChild3Name : "",
|
||||
// orgChild4: orgChild4 ? orgChild4.orgChild4Name : "",
|
||||
// })
|
||||
// .andWhere(
|
||||
// new Brackets((qb) => {
|
||||
// qb.orWhere(
|
||||
// searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
|
||||
// ? queryLike
|
||||
// : "1=1",
|
||||
// {
|
||||
// keyword: `%${searchKeyword}%`,
|
||||
// },
|
||||
// );
|
||||
// }),
|
||||
// )
|
||||
// .skip((page - 1) * pageSize)
|
||||
// .take(pageSize)
|
||||
// .getManyAndCount();
|
||||
|
||||
const data = await Promise.all(
|
||||
record.map((_data) => {
|
||||
// const posExecutive =
|
||||
// _data.current_holders.length == 0 ||
|
||||
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null ||
|
||||
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.positions.length ==
|
||||
// 0 ||
|
||||
// _data.current_holders
|
||||
// .find((x) => x.orgRevisionId == findRevision.id)
|
||||
// ?.positions.find((x: any) => x.positionIsSelected == true) == null ||
|
||||
// _data.current_holders
|
||||
// .find((x) => x.orgRevisionId == findRevision.id)
|
||||
// ?.positions.find((x: any) => x.positionIsSelected == true)?.posExecutive == null
|
||||
// ? null
|
||||
// : _data.current_holders
|
||||
// .find((x) => x.orgRevisionId == findRevision.id)
|
||||
// ?.positions.find((x: any) => x.positionIsSelected == true)?.posExecutive
|
||||
// ?.posExecutiveName;
|
||||
// const data = await Promise.all(
|
||||
// record.map((_data) => {
|
||||
// return {
|
||||
// id: _data.id,
|
||||
// avatar: _data.avatar,
|
||||
// avatarName: _data.avatarName,
|
||||
// dateAppoint: _data.dateAppoint,
|
||||
// prefix: _data.prefix,
|
||||
// rank: _data.rank,
|
||||
// firstName: _data.firstName,
|
||||
// lastName: _data.lastName,
|
||||
// citizenId: _data.citizenId,
|
||||
|
||||
// const shortName =
|
||||
// _data.current_holders.length == 0
|
||||
// ? null
|
||||
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 !=
|
||||
// null
|
||||
// ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
||||
// ?.orgChild3 != null
|
||||
// ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
||||
// ?.orgChild2 != null
|
||||
// ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
||||
// ?.orgChild1 != null
|
||||
// ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) !=
|
||||
// null &&
|
||||
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
|
||||
// ?.orgRoot != null
|
||||
// ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
|
||||
// : null;
|
||||
// const root =
|
||||
// _data.current_holders.length == 0 ||
|
||||
// (_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
|
||||
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null)
|
||||
// ? null
|
||||
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
|
||||
|
||||
// const child1 =
|
||||
// _data.current_holders == null ||
|
||||
// _data.current_holders.length == 0 ||
|
||||
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
||||
// ? null
|
||||
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1;
|
||||
|
||||
// const child2 =
|
||||
// _data.current_holders == null ||
|
||||
// _data.current_holders.length == 0 ||
|
||||
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
||||
// ? null
|
||||
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2;
|
||||
|
||||
// const child3 =
|
||||
// _data.current_holders == null ||
|
||||
// _data.current_holders.length == 0 ||
|
||||
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
||||
// ? null
|
||||
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3;
|
||||
|
||||
// const child4 =
|
||||
// _data.current_holders == null ||
|
||||
// _data.current_holders.length == 0 ||
|
||||
// _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
|
||||
// ? null
|
||||
// : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4;
|
||||
|
||||
// let _child1 = child1?.orgChild1Name;
|
||||
// let _child2 = child2?.orgChild2Name;
|
||||
// let _child3 = child3?.orgChild3Name;
|
||||
// let _child4 = child4?.orgChild4Name;
|
||||
|
||||
return {
|
||||
id: _data.id,
|
||||
avatar: _data.avatar,
|
||||
avatarName: _data.avatarName,
|
||||
dateAppoint: _data.dateAppoint,
|
||||
prefix: _data.prefix,
|
||||
rank: _data.rank,
|
||||
firstName: _data.firstName,
|
||||
lastName: _data.lastName,
|
||||
citizenId: _data.citizenId,
|
||||
|
||||
posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName,
|
||||
posType: _data.posType == null ? null : _data.posType.posTypeName,
|
||||
posLevelId: _data.posLevel == null ? null : _data.posLevel.id,
|
||||
posTypeId: _data.posType == null ? null : _data.posType.id,
|
||||
position: _data.position,
|
||||
posExecutive:
|
||||
_data.profileSalary[0].positionExecutive == null
|
||||
? null
|
||||
: _data.profileSalary[0].positionExecutive,
|
||||
posNo:
|
||||
_data.profileSalary[0].posNoAbb && _data.profileSalary[0].posNo
|
||||
? `${_data.profileSalary[0].posNoAbb} ${_data.profileSalary[0].posNo}`
|
||||
: _data.profileSalary[0].posNo || "",
|
||||
rootId: null,
|
||||
root: _data.profileSalary[0].orgRoot == null ? null : _data.profileSalary[0].orgRoot,
|
||||
orgRootShortName:
|
||||
_data.profileSalary[0].posNoAbb == null ? null : _data.profileSalary[0].posNoAbb,
|
||||
orgRevisionId: null,
|
||||
org:
|
||||
(_data.profileSalary[0].orgChild4 == null
|
||||
? ""
|
||||
: _data.profileSalary[0].orgChild4 + "\n") +
|
||||
(_data.profileSalary[0].orgChild3 == null
|
||||
? ""
|
||||
: _data.profileSalary[0].orgChild3 + "\n") +
|
||||
(_data.profileSalary[0].orgChild2 == null
|
||||
? ""
|
||||
: _data.profileSalary[0].orgChild2 + "\n") +
|
||||
(_data.profileSalary[0].orgChild1 == null
|
||||
? ""
|
||||
: _data.profileSalary[0].orgChild1 + "\n") +
|
||||
(_data.profileSalary[0].orgRoot == null ? "" : _data.profileSalary[0].orgRoot),
|
||||
};
|
||||
}),
|
||||
);
|
||||
// posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName,
|
||||
// posType: _data.posType == null ? null : _data.posType.posTypeName,
|
||||
// posLevelId: _data.posLevel == null ? null : _data.posLevel.id,
|
||||
// posTypeId: _data.posType == null ? null : _data.posType.id,
|
||||
// position: _data.position,
|
||||
// posExecutive:
|
||||
// _data.profileSalary[0].positionExecutive == null
|
||||
// ? null
|
||||
// : _data.profileSalary[0].positionExecutive,
|
||||
// posNo:
|
||||
// _data.profileSalary[0].posNoAbb && _data.profileSalary[0].posNo
|
||||
// ? `${_data.profileSalary[0].posNoAbb} ${_data.profileSalary[0].posNo}`
|
||||
// : _data.profileSalary[0].posNo || "",
|
||||
// rootId: null,
|
||||
// root: _data.profileSalary[0].orgRoot == null ? null : _data.profileSalary[0].orgRoot,
|
||||
// orgRootShortName:
|
||||
// _data.profileSalary[0].posNoAbb == null ? null : _data.profileSalary[0].posNoAbb,
|
||||
// orgRevisionId: null,
|
||||
// org:
|
||||
// (_data.profileSalary[0].orgChild4 == null
|
||||
// ? ""
|
||||
// : _data.profileSalary[0].orgChild4 + "\n") +
|
||||
// (_data.profileSalary[0].orgChild3 == null
|
||||
// ? ""
|
||||
// : _data.profileSalary[0].orgChild3 + "\n") +
|
||||
// (_data.profileSalary[0].orgChild2 == null
|
||||
// ? ""
|
||||
// : _data.profileSalary[0].orgChild2 + "\n") +
|
||||
// (_data.profileSalary[0].orgChild1 == null
|
||||
// ? ""
|
||||
// : _data.profileSalary[0].orgChild1 + "\n") +
|
||||
// (_data.profileSalary[0].orgRoot == null ? "" : _data.profileSalary[0].orgRoot),
|
||||
// };
|
||||
// }),
|
||||
// );
|
||||
|
||||
return new HttpSuccess({ data: data, total });
|
||||
}
|
||||
|
|
@ -6220,7 +6114,7 @@ export class ProfileController extends Controller {
|
|||
@Query() nodeId?: string,
|
||||
@Query() isAll?: boolean,
|
||||
@Query() retireType?: string,
|
||||
@Query() sortBy: string = "current_holders.posMasterNo",
|
||||
@Query() sortBy?: string,
|
||||
@Query() sort: "ASC" | "DESC" = "ASC",
|
||||
) {
|
||||
let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER");
|
||||
|
|
@ -6384,7 +6278,7 @@ export class ProfileController extends Controller {
|
|||
}),
|
||||
)
|
||||
.addSelect("CASE WHEN current_holders.posMasterNo IS NULL THEN 1 ELSE 0 END", "sort_order")
|
||||
.orderBy("sort_order", "ASC")
|
||||
.orderBy(`${sortBy ? sortBy : "sort_order"}`, `${sort}`)
|
||||
.addOrderBy("orgRoot.orgRootOrder", sort)
|
||||
.addOrderBy("orgChild1.orgChild1Order", sort)
|
||||
.addOrderBy("orgChild2.orgChild2Order", sort)
|
||||
|
|
@ -8568,7 +8462,7 @@ export class ProfileController extends Controller {
|
|||
system?: string;
|
||||
},
|
||||
@Query("sortBy") sortBy?: string,
|
||||
@Query("descending") descending?: boolean
|
||||
@Query("descending") descending?: boolean,
|
||||
) {
|
||||
// ค้นหารายชื่อถ้าไม่ส่ง system มาให้ default ตามทะเบียนประวัติ
|
||||
let _system: string = "SYS_REGISTRY_OFFICER";
|
||||
|
|
@ -8695,28 +8589,22 @@ export class ProfileController extends Controller {
|
|||
new Brackets((qb) => {
|
||||
qb.orWhere(body.keyword ? queryLike : "1=1", { keyword: `%${body.keyword}%` });
|
||||
}),
|
||||
)
|
||||
);
|
||||
|
||||
if (sortBy) {
|
||||
if(sortBy === "name"){
|
||||
query = query
|
||||
.orderBy(`profile.prefix`,descending ? "DESC" : "ASC")
|
||||
.addOrderBy(`profile.firstName`,descending ? "DESC" : "ASC")
|
||||
.addOrderBy(`profile.lastName`,descending ? "DESC" : "ASC")
|
||||
}else if(sortBy === "organization"){
|
||||
query = query.orderBy(
|
||||
`orgRoot.orgRootName`,
|
||||
descending ? "DESC" : "ASC"
|
||||
);
|
||||
}else{
|
||||
query = query.orderBy(
|
||||
`profile.${sortBy}`,
|
||||
descending ? "DESC" : "ASC"
|
||||
);
|
||||
}
|
||||
if (sortBy) {
|
||||
if (sortBy === "name") {
|
||||
query = query
|
||||
.orderBy(`profile.prefix`, descending ? "DESC" : "ASC")
|
||||
.addOrderBy(`profile.firstName`, descending ? "DESC" : "ASC")
|
||||
.addOrderBy(`profile.lastName`, descending ? "DESC" : "ASC");
|
||||
} else if (sortBy === "organization") {
|
||||
query = query.orderBy(`orgRoot.orgRootName`, descending ? "DESC" : "ASC");
|
||||
} else {
|
||||
query = query.orderBy(`profile.${sortBy}`, descending ? "DESC" : "ASC");
|
||||
}
|
||||
}
|
||||
|
||||
const [findProfile, total] = await query
|
||||
const [findProfile, total] = await query
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
|
|
@ -9276,40 +9164,25 @@ export class ProfileController extends Controller {
|
|||
},
|
||||
);
|
||||
}),
|
||||
)
|
||||
);
|
||||
|
||||
if (body.sortBy) {
|
||||
if(body.sortBy === "posLevelName"){
|
||||
query = query.orderBy(
|
||||
`posLevel.posLevelName`,
|
||||
body.descending ? "DESC" : "ASC"
|
||||
);
|
||||
}else if(body.sortBy === "posTypeName"){
|
||||
query = query.orderBy(
|
||||
`posType.posTypeName`,
|
||||
body.descending ? "DESC" : "ASC"
|
||||
);
|
||||
}else if(body.sortBy === "commandNo"){
|
||||
query = query.orderBy(
|
||||
`profileSalary.commandNo`,
|
||||
body.descending ? "DESC" : "ASC"
|
||||
);
|
||||
}else if(body.sortBy === "orgRootName"){
|
||||
query = query.orderBy(
|
||||
`orgRoot.orgRootName`,
|
||||
body.descending ? "DESC" : "ASC"
|
||||
);
|
||||
}else{
|
||||
query = query.orderBy(
|
||||
`profile.${body.sortBy}`,
|
||||
body.descending ? "DESC" : "ASC"
|
||||
);
|
||||
}
|
||||
}else{
|
||||
query = query.orderBy("profile.citizenId", "ASC")
|
||||
if (body.sortBy) {
|
||||
if (body.sortBy === "posLevelName") {
|
||||
query = query.orderBy(`posLevel.posLevelName`, body.descending ? "DESC" : "ASC");
|
||||
} else if (body.sortBy === "posTypeName") {
|
||||
query = query.orderBy(`posType.posTypeName`, body.descending ? "DESC" : "ASC");
|
||||
} else if (body.sortBy === "commandNo") {
|
||||
query = query.orderBy(`profileSalary.commandNo`, body.descending ? "DESC" : "ASC");
|
||||
} else if (body.sortBy === "orgRootName") {
|
||||
query = query.orderBy(`orgRoot.orgRootName`, body.descending ? "DESC" : "ASC");
|
||||
} else {
|
||||
query = query.orderBy(`profile.${body.sortBy}`, body.descending ? "DESC" : "ASC");
|
||||
}
|
||||
} else {
|
||||
query = query.orderBy("profile.citizenId", "ASC");
|
||||
}
|
||||
|
||||
const [findProfile, total] = await query
|
||||
const [findProfile, total] = await query
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
.take(body.pageSize)
|
||||
.getManyAndCount();
|
||||
|
|
@ -9924,38 +9797,29 @@ export class ProfileController extends Controller {
|
|||
},
|
||||
);
|
||||
}),
|
||||
)
|
||||
);
|
||||
|
||||
if (body.sortBy) {
|
||||
if(body.sortBy === "posType"){
|
||||
query = query.orderBy(
|
||||
`posType.posTypeName`,
|
||||
body.descending ? "DESC" : "ASC"
|
||||
);
|
||||
}else if(body.sortBy === "posLevel"){
|
||||
query = query.orderBy(
|
||||
`posLevel.posLevelName`,
|
||||
body.descending ? "DESC" : "ASC"
|
||||
);
|
||||
}else if(body.sortBy === "orgShortName" || body.sortBy === "posMasterNo"){
|
||||
query = query
|
||||
.orderBy(`orgRoot.orgRootShortName`,body.descending ? "DESC" : "ASC")
|
||||
.addOrderBy(`orgChild1.orgChild1ShortName`,body.descending ? "DESC" : "ASC")
|
||||
.addOrderBy(`orgChild2.orgChild2ShortName`,body.descending ? "DESC" : "ASC")
|
||||
.addOrderBy(`orgChild3.orgChild3ShortName`,body.descending ? "DESC" : "ASC")
|
||||
.addOrderBy(`orgChild4.orgChild4ShortName`,body.descending ? "DESC" : "ASC")
|
||||
.addOrderBy(`posMaster.posMasterNo`,body.descending ? "DESC" : "ASC")
|
||||
}else{
|
||||
query = query.orderBy(
|
||||
`current_holder.${body.sortBy}`,
|
||||
body.descending ? "DESC" : "ASC"
|
||||
);
|
||||
}
|
||||
}else{
|
||||
query = query.orderBy("current_holder.citizenId", "ASC")
|
||||
if (body.sortBy) {
|
||||
if (body.sortBy === "posType") {
|
||||
query = query.orderBy(`posType.posTypeName`, body.descending ? "DESC" : "ASC");
|
||||
} else if (body.sortBy === "posLevel") {
|
||||
query = query.orderBy(`posLevel.posLevelName`, body.descending ? "DESC" : "ASC");
|
||||
} else if (body.sortBy === "orgShortName" || body.sortBy === "posMasterNo") {
|
||||
query = query
|
||||
.orderBy(`orgRoot.orgRootShortName`, body.descending ? "DESC" : "ASC")
|
||||
.addOrderBy(`orgChild1.orgChild1ShortName`, body.descending ? "DESC" : "ASC")
|
||||
.addOrderBy(`orgChild2.orgChild2ShortName`, body.descending ? "DESC" : "ASC")
|
||||
.addOrderBy(`orgChild3.orgChild3ShortName`, body.descending ? "DESC" : "ASC")
|
||||
.addOrderBy(`orgChild4.orgChild4ShortName`, body.descending ? "DESC" : "ASC")
|
||||
.addOrderBy(`posMaster.posMasterNo`, body.descending ? "DESC" : "ASC");
|
||||
} else {
|
||||
query = query.orderBy(`current_holder.${body.sortBy}`, body.descending ? "DESC" : "ASC");
|
||||
}
|
||||
} else {
|
||||
query = query.orderBy("current_holder.citizenId", "ASC");
|
||||
}
|
||||
|
||||
const [findPosMaster, total] = await query
|
||||
const [findPosMaster, total] = await query
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
.take(body.pageSize)
|
||||
.getManyAndCount();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue