Merge branch 'develop' into dev
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m3s

* develop:
  หาคนเกษียณตามปี
  สิทธิ์ดูโครงสร้าง
This commit is contained in:
Warunee Tamkoo 2025-10-17 09:48:31 +07:00
commit ebea25597f
4 changed files with 68 additions and 499 deletions

View file

@ -42,6 +42,7 @@ import {
CreatePosMasterHistoryEmployee, CreatePosMasterHistoryEmployee,
CreatePosMasterHistoryOfficer, CreatePosMasterHistoryOfficer,
} from "../services/PositionService"; } from "../services/PositionService";
@Route("api/v1/org") @Route("api/v1/org")
@Tags("Organization") @Tags("Organization")
@Security("bearerAuth") @Security("bearerAuth")
@ -1962,34 +1963,41 @@ export class OrganizationController extends Controller {
child3: null, child3: null,
child4: null, child4: null,
}; };
let _data1: any = {
root: null,
};
const orgRevision = await this.orgRevisionRepository.findOne({ where: { id } }); const orgRevision = await this.orgRevisionRepository.findOne({ where: { id } });
if (!orgRevision) { if (!orgRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
} }
let attrOwnership = null;
let _privilege = await new permission().PermissionOrgList(request, "SYS_ORG"); let _privilege = await new permission().PermissionOrgList(request, "SYS_ORG");
attrOwnership = _privilege.root == null ? true : false; const attrOwnership = _privilege.root === null ? true : false;
if (
orgRevision.orgRevisionIsDraft == true && const profile = await this.profileRepo.findOne({
orgRevision.orgRevisionIsCurrent == false && where: { keycloak: request.user.sub },
attrOwnership == false relations: ["permissionProfiles", "current_holders", "current_holders.posMasterAssigns"],
) { });
const profile = await this.profileRepo.findOne({ if (!profile) {
where: { keycloak: request.user.sub }, throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งานในทะเบียนประวัติ");
relations: ["permissionProfiles"], }
}); let profileAssign = profile.current_holders
if (!profile) { ?.find((x) => x.orgRevisionId === id)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งานในทะเบียนประวัติ"); ?.posMasterAssigns.find((x) => x.assignId === "SYS_ORG");
if (orgRevision.orgRevisionIsDraft && !orgRevision.orgRevisionIsCurrent && !attrOwnership) {
_data.root = profile.permissionProfiles.map((x) => x.orgRootId);
}
// กำหนดการเข้าถึงข้อมูลตามสถานะและสิทธิ์
const isCurrentActive = !orgRevision.orgRevisionIsDraft && orgRevision.orgRevisionIsCurrent;
if (isCurrentActive) {
if (profileAssign) {
_data.root = [profile.current_holders.find((x) => x.orgRevisionId === id)?.orgRootId];
} else {
if (!attrOwnership) _data = _privilege;
} }
_data = {
root: profile.permissionProfiles.map((x) => x.orgRootId),
child1: null,
child2: null,
child3: null,
child4: null,
};
} }
const _revision = await this.orgRevisionRepository.findOne({ const _revision = await this.orgRevisionRepository.findOne({
@ -2001,8 +2009,8 @@ export class OrganizationController extends Controller {
.createQueryBuilder("orgRoot") .createQueryBuilder("orgRoot")
.where("orgRoot.orgRevisionId = :id", { id }) .where("orgRoot.orgRevisionId = :id", { id })
.andWhere( .andWhere(
_data.root != undefined && _data.root != null _data.root !== undefined && _data.root !== null
? _data.root[0] != null ? _data.root[0] !== null
? `orgRoot.id IN (:...node)` ? `orgRoot.id IN (:...node)`
: `orgRoot.id is null` : `orgRoot.id is null`
: "1=1", : "1=1",
@ -2040,8 +2048,8 @@ export class OrganizationController extends Controller {
.createQueryBuilder("orgChild1") .createQueryBuilder("orgChild1")
.where("orgChild1.orgRootId IN (:...ids)", { ids: orgRootIds }) .where("orgChild1.orgRootId IN (:...ids)", { ids: orgRootIds })
.andWhere( .andWhere(
_data.child1 != undefined && _data.child1 != null _data.child1 !== undefined && _data.child1 !== null
? _data.child1[0] != null ? _data.child1[0] !== null
? `orgChild1.id IN (:...node)` ? `orgChild1.id IN (:...node)`
: `orgChild1.id is null` : `orgChild1.id is null`
: "1=1", : "1=1",
@ -2081,8 +2089,8 @@ export class OrganizationController extends Controller {
.createQueryBuilder("orgChild2") .createQueryBuilder("orgChild2")
.where("orgChild2.orgChild1Id IN (:...ids)", { ids: orgChild1Ids }) .where("orgChild2.orgChild1Id IN (:...ids)", { ids: orgChild1Ids })
.andWhere( .andWhere(
_data.child2 != undefined && _data.child2 != null _data.child2 !== undefined && _data.child2 !== null
? _data.child2[0] != null ? _data.child2[0] !== null
? `orgChild2.id IN (:...node)` ? `orgChild2.id IN (:...node)`
: `orgChild2.id is null` : `orgChild2.id is null`
: "1=1", : "1=1",
@ -2121,8 +2129,8 @@ export class OrganizationController extends Controller {
.createQueryBuilder("orgChild3") .createQueryBuilder("orgChild3")
.where("orgChild3.orgChild2Id IN (:...ids)", { ids: orgChild2Ids }) .where("orgChild3.orgChild2Id IN (:...ids)", { ids: orgChild2Ids })
.andWhere( .andWhere(
_data.child3 != undefined && _data.child3 != null _data.child3 !== undefined && _data.child3 !== null
? _data.child3[0] != null ? _data.child3[0] !== null
? `orgChild3.id IN (:...node)` ? `orgChild3.id IN (:...node)`
: `orgChild3.id is null` : `orgChild3.id is null`
: "1=1", : "1=1",
@ -2161,8 +2169,8 @@ export class OrganizationController extends Controller {
.createQueryBuilder("orgChild4") .createQueryBuilder("orgChild4")
.where("orgChild4.orgChild3Id IN (:...ids)", { ids: orgChild3Ids }) .where("orgChild4.orgChild3Id IN (:...ids)", { ids: orgChild3Ids })
.andWhere( .andWhere(
_data.child4 != undefined && _data.child4 != null _data.child4 !== undefined && _data.child4 !== null
? _data.child4[0] != null ? _data.child4[0] !== null
? `orgChild4.id IN (:...node)` ? `orgChild4.id IN (:...node)`
: `orgChild4.id is null` : `orgChild4.id is null`
: "1=1", : "1=1",
@ -2194,7 +2202,6 @@ export class OrganizationController extends Controller {
.getMany() .getMany()
: []; : [];
// const formattedData = orgRootData.map((orgRoot) => {
const formattedData = await Promise.all( const formattedData = await Promise.all(
orgRootData.map(async (orgRoot) => { orgRootData.map(async (orgRoot) => {
return { return {
@ -2223,91 +2230,6 @@ export class OrganizationController extends Controller {
responsibility: orgRoot.responsibility, responsibility: orgRoot.responsibility,
labelName: labelName:
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName, orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
// totalPosition: await this.posMasterRepository.count({
// where: { orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id },
// }),
// totalPositionCurrentUse: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// current_holderId: Not(IsNull()) || Not(""),
// },
// }),
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextUse: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// next_holderId: Not(IsNull()) || Not(""),
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// next_holderId: IsNull() || "",
// },
// }),
// totalRootPosition: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: IsNull() || "",
// orgChild2Id: IsNull() || "",
// orgChild3Id: IsNull() || "",
// orgChild4Id: IsNull() || "",
// },
// }),
// totalRootPositionCurrentUse: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: IsNull() || "",
// orgChild2Id: IsNull() || "",
// orgChild3Id: IsNull() || "",
// orgChild4Id: IsNull() || "",
// current_holderId: Not(IsNull()) || Not(""),
// },
// }),
// totalRootPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: IsNull() || "",
// orgChild2Id: IsNull() || "",
// orgChild3Id: IsNull() || "",
// orgChild4Id: IsNull() || "",
// current_holderId: IsNull() || "",
// },
// }),
// totalRootPositionNextUse: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: IsNull() || "",
// orgChild2Id: IsNull() || "",
// orgChild3Id: IsNull() || "",
// orgChild4Id: IsNull() || "",
// next_holderId: Not(IsNull()) || Not(""),
// },
// }),
// totalRootPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: IsNull() || "",
// orgChild2Id: IsNull() || "",
// orgChild3Id: IsNull() || "",
// orgChild4Id: IsNull() || "",
// next_holderId: IsNull() || "",
// },
// }),
children: await Promise.all( children: await Promise.all(
orgChild1Data orgChild1Data
@ -2352,91 +2274,6 @@ export class OrganizationController extends Controller {
"00" + "00" +
" " + " " +
orgRoot.orgRootShortName, orgRoot.orgRootShortName,
// totalPosition: await this.posMasterRepository.count({
// where: { orgRevisionId: orgRoot.orgRevisionId, orgChild1Id: orgChild1.id },
// }),
// totalPositionCurrentUse: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgChild1Id: orgChild1.id,
// current_holderId: Not(IsNull()) || Not(""),
// },
// }),
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgChild1Id: orgChild1.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextUse: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgChild1Id: orgChild1.id,
// next_holderId: Not(IsNull()) || Not(""),
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgChild1Id: orgChild1.id,
// next_holderId: IsNull() || "",
// },
// }),
// totalRootPosition: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: IsNull() || "",
// orgChild3Id: IsNull() || "",
// orgChild4Id: IsNull() || "",
// },
// }),
// totalRootPositionCurrentUse: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: IsNull() || "",
// orgChild3Id: IsNull() || "",
// orgChild4Id: IsNull() || "",
// current_holderId: Not(IsNull()) || Not(""),
// },
// }),
// totalRootPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: IsNull() || "",
// orgChild3Id: IsNull() || "",
// orgChild4Id: IsNull() || "",
// current_holderId: IsNull() || "",
// },
// }),
// totalRootPositionNextUse: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: IsNull() || "",
// orgChild3Id: IsNull() || "",
// orgChild4Id: IsNull() || "",
// next_holderId: Not(IsNull()) || Not(""),
// },
// }),
// totalRootPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: IsNull() || "",
// orgChild3Id: IsNull() || "",
// orgChild4Id: IsNull() || "",
// next_holderId: IsNull() || "",
// },
// }),
children: await Promise.all( children: await Promise.all(
orgChild2Data orgChild2Data
@ -2486,94 +2323,6 @@ export class OrganizationController extends Controller {
"00" + "00" +
" " + " " +
orgRoot.orgRootShortName, orgRoot.orgRootShortName,
// totalPosition: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgChild2Id: orgChild2.id,
// },
// }),
// totalPositionCurrentUse: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgChild2Id: orgChild2.id,
// current_holderId: Not(IsNull()) || Not(""),
// },
// }),
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgChild2Id: orgChild2.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextUse: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgChild2Id: orgChild2.id,
// next_holderId: Not(IsNull()) || Not(""),
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgChild2Id: orgChild2.id,
// next_holderId: IsNull() || "",
// },
// }),
// totalRootPosition: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: IsNull() || "",
// orgChild4Id: IsNull() || "",
// },
// }),
// totalRootPositionCurrentUse: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: IsNull() || "",
// orgChild4Id: IsNull() || "",
// current_holderId: Not(IsNull()) || Not(""),
// },
// }),
// totalRootPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: IsNull() || "",
// orgChild4Id: IsNull() || "",
// current_holderId: IsNull() || "",
// },
// }),
// totalRootPositionNextUse: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: IsNull() || "",
// orgChild4Id: IsNull() || "",
// next_holderId: Not(IsNull()) || Not(""),
// },
// }),
// totalRootPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: IsNull() || "",
// orgChild4Id: IsNull() || "",
// next_holderId: IsNull() || "",
// },
// }),
children: await Promise.all( children: await Promise.all(
orgChild3Data orgChild3Data
@ -2630,94 +2379,6 @@ export class OrganizationController extends Controller {
"00" + "00" +
" " + " " +
orgRoot.orgRootShortName, orgRoot.orgRootShortName,
// totalPosition: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgChild3Id: orgChild3.id,
// },
// }),
// totalPositionCurrentUse: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgChild3Id: orgChild3.id,
// current_holderId: Not(IsNull()) || Not(""),
// },
// }),
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgChild3Id: orgChild3.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextUse: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgChild3Id: orgChild3.id,
// next_holderId: Not(IsNull()) || Not(""),
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgChild3Id: orgChild3.id,
// next_holderId: IsNull() || "",
// },
// }),
// totalRootPosition: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: orgChild3.id,
// orgChild4Id: IsNull() || "",
// },
// }),
// totalRootPositionCurrentUse: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: orgChild3.id,
// orgChild4Id: IsNull() || "",
// current_holderId: Not(IsNull()) || Not(""),
// },
// }),
// totalRootPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: orgChild3.id,
// orgChild4Id: IsNull() || "",
// current_holderId: IsNull() || "",
// },
// }),
// totalRootPositionNextUse: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: orgChild3.id,
// orgChild4Id: IsNull() || "",
// next_holderId: Not(IsNull()) || Not(""),
// },
// }),
// totalRootPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: orgChild3.id,
// orgChild4Id: IsNull() || "",
// next_holderId: IsNull() || "",
// },
// }),
children: await Promise.all( children: await Promise.all(
orgChild4Data orgChild4Data
@ -2781,99 +2442,6 @@ export class OrganizationController extends Controller {
"00" + "00" +
" " + " " +
orgRoot.orgRootShortName, orgRoot.orgRootShortName,
// totalPosition: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgChild4Id: orgChild4.id,
// },
// }),
// totalPositionCurrentUse: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgChild4Id: orgChild4.id,
// current_holderId: Not(IsNull()) || Not(""),
// },
// }),
// totalPositionCurrentVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgChild4Id: orgChild4.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalPositionNextUse: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgChild4Id: orgChild4.id,
// next_holderId: Not(IsNull()) || Not(""),
// },
// }),
// totalPositionNextVacant: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgChild4Id: orgChild4.id,
// next_holderId: IsNull() || "",
// },
// }),
// totalRootPosition: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: orgChild3.id,
// orgChild4Id: orgChild4.id,
// },
// }),
// totalRootPositionCurrentUse: await this.posMasterRepository.count(
// {
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: orgChild3.id,
// orgChild4Id: orgChild4.id,
// current_holderId: Not(IsNull()) || Not(""),
// },
// },
// ),
// totalRootPositionCurrentVacant:
// await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: orgChild3.id,
// orgChild4Id: orgChild4.id,
// current_holderId: IsNull() || "",
// },
// }),
// totalRootPositionNextUse: await this.posMasterRepository.count({
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: orgChild3.id,
// orgChild4Id: orgChild4.id,
// next_holderId: Not(IsNull()) || Not(""),
// },
// }),
// totalRootPositionNextVacant: await this.posMasterRepository.count(
// {
// where: {
// orgRevisionId: orgRoot.orgRevisionId,
// orgRootId: orgRoot.id,
// orgChild1Id: orgChild1.id,
// orgChild2Id: orgChild2.id,
// orgChild3Id: orgChild3.id,
// orgChild4Id: orgChild4.id,
// next_holderId: IsNull() || "",
// },
// },
// ),
})), })),
), ),
})), })),
@ -2886,6 +2454,7 @@ export class OrganizationController extends Controller {
}), }),
); );
// return new HttpSuccess({ remark: _revision.remark, data: formattedData });
return new HttpSuccess({ remark: _revision.remark, data: formattedData }); return new HttpSuccess({ remark: _revision.remark, data: formattedData });
} }

View file

@ -4975,7 +4975,7 @@ export class ProfileController extends Controller {
* *
*/ */
@Post("cal/retire") @Post("cal/retire")
async calDateRetire(@Body() body:{birthDate: Date}) { async calDateRetire(@Body() body: { birthDate: Date }) {
const retireDate = await calculateRetireDate(body.birthDate); const retireDate = await calculateRetireDate(body.birthDate);
const age = calculateAge(body.birthDate); const age = calculateAge(body.birthDate);
@ -10436,7 +10436,11 @@ export class ProfileController extends Controller {
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4") .leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.leftJoinAndSelect("current_holders.positions", "positions") .leftJoinAndSelect("current_holders.positions", "positions")
.leftJoinAndSelect("positions.posExecutive", "posExecutive") .leftJoinAndSelect("positions.posExecutive", "posExecutive")
.where("YEAR(profile.dateRetire) = :year", { year }) // calculate range: start = 2 Oct of (year-1), end = 1 Oct of year (inclusive)
.where("profile.dateRetire BETWEEN :start AND :end", {
start: `${year - 1}-10-02`,
end: `${year}-10-01`,
})
.getMany(); .getMany();
if (!profiles || profiles.length === 0) { if (!profiles || profiles.length === 0) {

View file

@ -5032,7 +5032,11 @@ export class ProfileEmployeeController extends Controller {
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3") .leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4") .leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.leftJoinAndSelect("current_holders.positions", "positions") .leftJoinAndSelect("current_holders.positions", "positions")
.where("YEAR(profileEmployee.dateRetire) = :year", { year }) // calculate range: start = 2 Oct of (year-1), end = 1 Oct of year (inclusive)
.where("profile.dateRetire BETWEEN :start AND :end", {
start: `${year - 1}-10-02`,
end: `${year}-10-01`,
})
.getMany(); .getMany();
if (!profiles || profiles.length === 0) { if (!profiles || profiles.length === 0) {

View file

@ -1527,7 +1527,7 @@ export class ProfileEmployeeTempController extends Controller {
if (!findRevision) { if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
} }
let query = await this.profileRepo let query = await this.profileRepo
.createQueryBuilder("profileEmployee") .createQueryBuilder("profileEmployee")
.leftJoinAndSelect("profileEmployee.posLevel", "posLevel") .leftJoinAndSelect("profileEmployee.posLevel", "posLevel")
@ -1640,36 +1640,24 @@ export class ProfileEmployeeTempController extends Controller {
} }
} }
}), }),
) );
if (sortBy) { if (sortBy) {
if(sortBy == "posLevel"){ if (sortBy == "posLevel") {
query = query.orderBy( query = query.orderBy(`posLevel.posLevelName`, descending ? "DESC" : "ASC");
`posLevel.posLevelName`, } else if (sortBy == "posType") {
descending ? "DESC" : "ASC" query = query.orderBy(`posType.posTypeName`, descending ? "DESC" : "ASC");
); } else if (sortBy == "govAge") {
}else if(sortBy == "posType"){ query = query.orderBy(`profileEmployee.dateAppoint`, descending ? "DESC" : "ASC");
query = query.orderBy( } else {
`posType.posTypeName`, query = query.orderBy(`profileEmployee.${sortBy}`, descending ? "DESC" : "ASC");
descending ? "DESC" : "ASC"
);
}else if(sortBy == "govAge"){
query = query.orderBy(
`profileEmployee.dateAppoint`,
descending ? "DESC" : "ASC"
);
}else{
query = query.orderBy(
`profileEmployee.${sortBy}`,
descending ? "DESC" : "ASC"
);
} }
} }
const [record, total] = await query const [record, total] = await query
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
.take(pageSize) .take(pageSize)
.getManyAndCount(); .getManyAndCount();
const data = await Promise.all( const data = await Promise.all(
record.map((_data) => { record.map((_data) => {
@ -3241,7 +3229,11 @@ export class ProfileEmployeeTempController extends Controller {
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4") .leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.leftJoinAndSelect("current_holders.positions", "positions") .leftJoinAndSelect("current_holders.positions", "positions")
// .leftJoinAndSelect("positions.posExecutive", "posExecutive") // .leftJoinAndSelect("positions.posExecutive", "posExecutive")
.where("YEAR(profileEmployee.dateRetire) = :year", { year }) // calculate range: start = 2 Oct of (year-1), end = 1 Oct of year (inclusive)
.where("profile.dateRetire BETWEEN :start AND :end", {
start: `${year - 1}-10-02`,
end: `${year}-10-01`,
})
.getMany(); .getMany();
if (!profiles || profiles.length === 0) { if (!profiles || profiles.length === 0) {