ค้นหาประวัติการครองตำแหน่ง ขรก./ลูกจ้าง
This commit is contained in:
parent
8f74e3a366
commit
77e3248a3a
4 changed files with 135 additions and 2 deletions
|
|
@ -526,6 +526,71 @@ export class ProfileEmployeeController extends Controller {
|
|||
return new HttpSuccess({ data: data, total });
|
||||
}
|
||||
|
||||
/**
|
||||
* API ค้นหาประวัติการครองตำแหน่ง ลูกจ้าง
|
||||
*
|
||||
* @summary ค้นหาประวัติการครองตำแหน่ง ลูกจ้าง
|
||||
*
|
||||
*/
|
||||
@Post("search/history/oc")
|
||||
async searchHistoryOC(
|
||||
@Body()
|
||||
requestBody: {
|
||||
posNo?: string;
|
||||
position?: string;
|
||||
},
|
||||
) {
|
||||
const profiles = await this.profileRepo
|
||||
.createQueryBuilder("profileEmployee")
|
||||
.leftJoinAndSelect("profileEmployee.profileSalarys", "profileSalarys")
|
||||
.select([
|
||||
"profileEmployee.id",
|
||||
"profileEmployee.prefix",
|
||||
"profileEmployee.firstName",
|
||||
"profileEmployee.lastName",
|
||||
"profileEmployee.citizenId",
|
||||
"profileSalarys.position",
|
||||
"profileSalarys.posNo",
|
||||
"profileSalarys.date"
|
||||
])
|
||||
.andWhere(
|
||||
requestBody.position != null && requestBody.position != "" && requestBody.posNo == undefined
|
||||
? "profileSalarys.position LIKE :position"
|
||||
: "1=2",
|
||||
{
|
||||
position: `%${requestBody.position}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
requestBody.posNo != null && requestBody.posNo != "" && requestBody.position == undefined
|
||||
? "profileSalarys.posNo LIKE :posNo"
|
||||
: "1=2",
|
||||
{
|
||||
posNo: `%${requestBody.posNo}%`,
|
||||
},
|
||||
)
|
||||
.getMany();
|
||||
|
||||
const mapData = profiles.map(profile => {
|
||||
let profileSalary;
|
||||
if (profile.profileSalarys && profile.profileSalarys.length > 0) {
|
||||
profileSalary = profile.profileSalarys.reduce((latest, current) => {
|
||||
return new Date(current.date) > new Date(latest.date) ? current : latest;
|
||||
});
|
||||
}
|
||||
return {
|
||||
id: profile.id,
|
||||
fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`,
|
||||
citizenId: profile.citizenId,
|
||||
position: profileSalary ? profileSalary.position : null,
|
||||
posNo: profileSalary ? profileSalary.posNo : null,
|
||||
date: profileSalary ? profileSalary.date : null
|
||||
};
|
||||
});
|
||||
|
||||
return new HttpSuccess(mapData);
|
||||
}
|
||||
|
||||
/**
|
||||
* API ข้อมูลทะเบียนประวัติตาม keycloak
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue