fix and add api(/search-personal-no-keycloak)

This commit is contained in:
AdisakKanthawilang 2024-06-13 14:49:50 +07:00
parent b7ce71d017
commit 8a1f2506bb
3 changed files with 360 additions and 7 deletions

View file

@ -1505,11 +1505,10 @@ export class ProfileEmployeeController extends Controller {
(x) => x.orgRevisionId == findRevision.id,
)?.posMasterNo;
const latestProfileEducation = await this.profileEducationRepository.findOne({
where: { profileEmployeeId: item.id },
order: { endDate: "DESC" },
});
const latestProfileEducation = await this.profileEducationRepository.findOne({
where: { profileEmployeeId: item.id },
order: { endDate: "DESC" },
});
return {
id: item.id,
@ -2910,4 +2909,171 @@ export class ProfileEmployeeController extends Controller {
);
return new HttpSuccess();
}
/**
* API keycloak
*
* @summary keycloak
*
*/
@Post("search-personal-no-keycloak")
async getProfileBySearchKeywordNoKeyCloak(
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Body()
body: {
fieldName: string;
keyword?: string;
},
) {
let findProfile: any;
let total: any;
const skip = (page - 1) * pageSize;
const take = pageSize;
switch (body.fieldName) {
case "idcard":
[findProfile, total] = await this.profileRepo.findAndCount({
where: {
keycloak: IsNull(),
citizenId: Like(`%${body.keyword}%`),
},
relations: ["posType", "posLevel", "current_holders", "profileSalarys"],
skip,
take,
});
break;
case "firstname":
[findProfile, total] = await this.profileRepo.findAndCount({
where: {
keycloak: IsNull(),
firstName: Like(`%${body.keyword}%`),
},
relations: ["posType", "posLevel", "current_holders", "profileSalarys"],
skip,
take,
});
break;
case "lastname":
[findProfile, total] = await this.profileRepo.findAndCount({
where: {
keycloak: IsNull(),
lastName: Like(`%${body.keyword}%`),
},
relations: ["posType", "posLevel", "current_holders", "profileSalarys"],
skip,
take,
});
break;
default:
[findProfile, total] = await this.profileRepo.findAndCount({
where: {
keycloak: IsNull(),
},
relations: ["posType", "posLevel", "current_holders", "profileSalarys"],
skip,
take,
});
break;
}
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
}
const mapDataProfile = await Promise.all(
findProfile.map(async (item: ProfileEmployee) => {
const fullName = `${item.prefix} ${item.firstName} ${item.lastName}`;
const shortName =
item.current_holders.length == 0
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 !=
null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3 !=
null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild2 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild1 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id) !=
null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgRoot != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: null;
const root =
item.current_holders.length == 0 ||
(item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null)
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
let salary: any = "";
if (item != null && item.profileSalarys != null && item.profileSalarys.length > 0) {
let _salary: any = item.profileSalarys.sort(
(a, b) =>
(b.date == null ? 0 : b.date.getTime()) - (a.date == null ? 0 : a.date.getTime()),
);
if (_salary.length > 0) {
salary = _salary[0];
}
}
const posMasterNo = item.current_holders?.find(
(x) => x.orgRevisionId == findRevision.id,
)?.posMasterNo;
const latestProfileEducation = await this.profileEducationRepository.findOne({
where: { profileEmployeeId: item.id },
order: { endDate: "DESC" },
});
return {
id: item.id,
prefix: item.prefix,
rank: item.rank,
firstName: item.firstName,
lastName: item.lastName,
position: item.position,
idcard: item.citizenId,
email: item.email,
phone: item.phone,
name: fullName,
birthDate: item.birthDate,
positionLevel: item.posLevelId,
positionLevelName: item.posLevel?.posLevelName,
positionType: item.posTypeId,
positionTypeName: item.posType?.posTypeName,
posNo: shortName,
organization: root == null ? null : root.orgRootShortName,
salary: salary == "" ? "" : salary.amount,
posMasterNo: posMasterNo ?? null,
posTypeId: item.posTypeId,
posTypeName: item.posType?.posTypeName,
posLevelId: item.posLevelId,
posLevelName: item.posLevel?.posLevelName,
educationDegree:
latestProfileEducation != null && latestProfileEducation.educationLevel != null
? latestProfileEducation.educationLevel
: null,
};
}),
);
return new HttpSuccess({ data: mapDataProfile, total });
}
}