ค้นหาประวัติการครองตำแหน่ง ขรก./ลูกจ้าง

This commit is contained in:
Bright 2024-05-20 15:23:26 +07:00
parent 8f74e3a366
commit 77e3248a3a
4 changed files with 135 additions and 2 deletions

View file

@ -815,6 +815,74 @@ export class ProfileController 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("profile")
.leftJoinAndSelect("profile.profileSalary", "profileSalary")
.select([
"profile.id",
"profile.prefix",
"profile.firstName",
"profile.lastName",
"profile.citizenId",
"profileSalary.position",
"profileSalary.posNo",
"profileSalary.date"
])
.andWhere(
requestBody.position != null && requestBody.position != "" && requestBody.posNo == undefined
? "profileSalary.position LIKE :position"
: "1=2",
{
position: `%${requestBody.position}%`,
},
)
.orWhere(
requestBody.posNo != null && requestBody.posNo != "" && requestBody.position == undefined
? "profileSalary.posNo LIKE :posNo"
: "1=2",
{
posNo: `%${requestBody.posNo}%`,
},
)
.getMany();
const mapData = profiles.map(profile => {
let profileSalary;
if (profile.profileSalary && profile.profileSalary.length > 0) {
profileSalary = profile.profileSalary.reduce((latest, current) => {
return new Date(current.date) > new Date(latest.date) ? current : latest;
});
}
return {
id: profile.id,
// prefix: profile.prefix,
// firstName: profile.firstName,
// lastName: profile.lastName,
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
*