Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop

This commit is contained in:
Kittapath 2024-05-20 15:27:56 +07:00
commit f6bdfce063
5 changed files with 138 additions and 3 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
*

View file

@ -79,7 +79,9 @@ export class ProfileEducationsEmployeeController extends Controller {
],
})
public async detailProfileEducation(@Path() profileEmployeeId: string) {
const getProfileEducation = await this.profileEducationRepo.findBy({ profileEmployeeId });
const getProfileEducation = await this.profileEducationRepo.find({
where: { profileEmployeeId: profileEmployeeId}
});
if (!getProfileEducation) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}

View file

@ -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
*

View file

@ -282,7 +282,7 @@ export class ProfileEmployee extends EntityBase {
@OneToMany(() => EmployeePosMaster, (v) => v.next_holder)
next_holders: EmployeePosMaster[];
@OneToMany(() => ProfileSalary, (v) => v.profile)
@OneToMany(() => ProfileSalary, (v) => v.profileEmployee)
profileSalarys: ProfileSalary[];
@OneToMany(() => ProfileCertificate, (v) => v.profileEmployee)

View file

@ -149,7 +149,7 @@ export class ProfileSalary extends EntityBase {
@JoinColumn({ name: "profileId" })
profile: Profile;
@ManyToOne(() => ProfileEmployee, (ProfileEmployee) => ProfileEmployee.profileSalarys)
@ManyToOne(() => ProfileEmployee, (profileEmployee) => profileEmployee.profileSalarys)
@JoinColumn({ name: "profileEmployeeId" })
profileEmployee: ProfileEmployee;
}