This commit is contained in:
AdisakKanthawilang 2024-02-27 17:20:48 +07:00
parent e147412ea4
commit 65f91cd327

View file

@ -255,10 +255,10 @@ export class ProfileController extends Controller {
*
*/
@Get()
async listProfile(
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string,
async listProfile(
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string,
) {
const [profile, total] = await this.profileRepository.findAndCount({
select: [
@ -279,15 +279,9 @@ export class ProfileController extends Controller {
const formattedKeyword = keyword.toLowerCase().replace(/\s+/g, "");
const filteredProfile = profile.filter(
(x) =>
(
x.prefix +
x.firstName +
x.lastName
)
.replace(/\s+/g, "")
.includes(formattedKeyword) ||
(x.prefix + x.firstName + x.lastName).replace(/\s+/g, "").includes(formattedKeyword) ||
x.citizenId?.toString().includes(keyword) ||
x.position?.toString().includes(keyword)
x.position?.toString().includes(keyword),
);
const formattedData = filteredProfile.map((item) => ({
@ -298,7 +292,7 @@ export class ProfileController extends Controller {
citizenId: item.citizenId,
position: item.position,
posLevelId: item.posLevelId,
posTypeId: item.posTypeId
posTypeId: item.posTypeId,
}));
return new HttpSuccess({ data: formattedData, total: formattedData.length });
@ -316,10 +310,9 @@ export class ProfileController extends Controller {
citizenId: item.citizenId,
position: item.position,
posLevelId: item.posLevelId,
posTypeId: item.posTypeId
posTypeId: item.posTypeId,
}));
return new HttpSuccess({ data: formattedData, total });
}
/**
@ -866,4 +859,104 @@ export class ProfileController extends Controller {
throw new Error(error);
}
}
/**
* API
*
* @summary ORG_072 - #76
*
*/
@Get("salary/gen")
async salaryGen() {
const findRevision = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. OrgRevision");
}
const findPosMaster = await AppDataSource.getRepository(PosMaster)
.createQueryBuilder("posMaster")
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
.leftJoinAndSelect("posMaster.orgRoot", "orgRoot")
.leftJoinAndSelect("posMaster.orgChild1", "orgChild1")
.leftJoinAndSelect("posMaster.orgChild2", "orgChild2")
.leftJoinAndSelect("posMaster.orgChild3", "orgChild3")
.leftJoinAndSelect("posMaster.orgChild4", "orgChild4")
.leftJoinAndSelect("posMaster.positions", "positions")
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
.leftJoinAndSelect("current_holder.profileSalary", "profileSalary")
.where({
orgRevisionId: findRevision?.id,
current_holderId: Not(IsNull()),
})
.getMany();
if (!findPosMaster) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. PosMaster");
}
const formattedData = findPosMaster.map((item) => {
let orgShortName = "";
if (item.orgChild1Id === null) {
orgShortName = item.orgRoot?.orgRootShortName;
} else if (item.orgChild2Id === null) {
orgShortName = item.orgChild1?.orgChild1ShortName;
} else if (item.orgChild3Id === null) {
orgShortName = item.orgChild2?.orgChild2ShortName;
} else if (item.orgChild4Id === null) {
orgShortName = item.orgChild3?.orgChild3ShortName;
} else {
orgShortName = item.orgChild4?.orgChild4ShortName;
}
const posExecutive =
item.positions == null ||
item.positions?.find((position) => position.positionIsSelected ==true) == null ||
item.positions?.find((position) => position.positionIsSelected ==true)?.posExecutive == null ||
item.positions?.find((position) => position.positionIsSelected ==true)?.posExecutive?.posExecutiveName == null
? null
: item.positions?.find((position) => position.positionIsSelected ==true)?.posExecutive
.posExecutiveName;
const amount =
item.current_holder == null ||
item.current_holder.profileSalary.length == 0
? null
: item.current_holder.profileSalary.sort((a:any, b:any) => b.date - a.date)[0].amount;
return {
prefix: item.current_holder.prefix,
firstName: item.current_holder.firstName,
lastName: item.current_holder.lastName,
citizenId: item.current_holder.citizenId,
posMasterNoPrefix: item.posMasterNoPrefix,
posMasterNo: item.posMasterNo,
posMasterNoSuffix: item.posMasterNoSuffix,
orgShortName: orgShortName,
position: item.current_holder.position,
posTypeId: item.current_holder.posTypeId,
posLevelId: item.current_holder.posLevelId,
posExecutive: posExecutive,
amount: amount,
rootId: item.orgRootId,
root: item.orgRoot?.orgRootName,
child1Id: item.orgChild1Id,
child1: item.orgChild1?.orgChild1Name,
child2Id: item.orgChild2Id,
child2: item.orgChild2?.orgChild2Name,
child3Id: item.orgChild3Id,
child3: item.orgChild3?.orgChild3Name,
child4Id: item.orgChild4Id,
child4: item.orgChild4?.orgChild4Name,
isResult: true,
isDuration: false,
isPunish: true,
isRetired: false,
isRetired2: true,
};
});
return new HttpSuccess(formattedData);
}
}