แก้ค้นหาลูกจ้าง

This commit is contained in:
Kittapath 2024-05-23 15:37:13 +07:00
parent 689d48aadc
commit 852525c8f5
2 changed files with 49 additions and 42 deletions

View file

@ -35,6 +35,8 @@ import { OrgChild4 } from "../entities/OrgChild4";
import { Position } from "../entities/Position"; import { Position } from "../entities/Position";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { EmployeePosMaster } from "../entities/EmployeePosMaster"; import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { EmployeePosType } from "../entities/EmployeePosType";
import { EmployeePosLevel } from "../entities/EmployeePosLevel";
@Route("api/v1/org/pos") @Route("api/v1/org/pos")
@Tags("Position") @Tags("Position")
@Security("bearerAuth") @Security("bearerAuth")
@ -47,6 +49,8 @@ export class PositionController extends Controller {
private posExecutiveRepository = AppDataSource.getRepository(PosExecutive); private posExecutiveRepository = AppDataSource.getRepository(PosExecutive);
private posTypeRepository = AppDataSource.getRepository(PosType); private posTypeRepository = AppDataSource.getRepository(PosType);
private posLevelRepository = AppDataSource.getRepository(PosLevel); private posLevelRepository = AppDataSource.getRepository(PosLevel);
private posTypeEmployeeRepository = AppDataSource.getRepository(EmployeePosType);
private posLevelEmployeeRepository = AppDataSource.getRepository(EmployeePosLevel);
private posDictRepository = AppDataSource.getRepository(PosDict); private posDictRepository = AppDataSource.getRepository(PosDict);
private posMasterRepository = AppDataSource.getRepository(PosMaster); private posMasterRepository = AppDataSource.getRepository(PosMaster);
private positionRepository = AppDataSource.getRepository(Position); private positionRepository = AppDataSource.getRepository(Position);
@ -2759,10 +2763,10 @@ export class PositionController extends Controller {
let typeCondition: any = {}; let typeCondition: any = {};
let conditionA: any = null; let conditionA: any = null;
let posType = await this.posTypeRepository.findOne({ let posType = await this.posTypeEmployeeRepository.findOne({
where: { id: String(body.posType) }, where: { id: String(body.posType) },
}); });
let posLevel = await this.posLevelRepository.findOne({ let posLevel = await this.posLevelEmployeeRepository.findOne({
where: { id: String(body.posLevel) }, where: { id: String(body.posLevel) },
}); });

View file

@ -77,7 +77,7 @@ export class ProfileController extends Controller {
const orgRevision = await this.orgRevisionRepo.findOne({ const orgRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true }, where: { orgRevisionIsCurrent: true },
}); });
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
relations: [ relations: [
"profileSalary", "profileSalary",
@ -87,16 +87,20 @@ export class ProfileController extends Controller {
"current_holders.orgChild1", "current_holders.orgChild1",
"current_holders.orgChild2", "current_holders.orgChild2",
"current_holders.orgChild3", "current_holders.orgChild3",
"current_holders.orgChild4" "current_holders.orgChild4",
], ],
where: { id: id, }, where: { id: id },
}); });
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const province = await this.provinceRepository.findOneBy({ id: profile.registrationProvinceId }) const province = await this.provinceRepository.findOneBy({
const district = await this.districtRepository.findOneBy({ id: profile.registrationDistrictId }) id: profile.registrationProvinceId,
const subDistrict = await this.subDistrict.findOneBy({ id: profile.registrationSubDistrictId }) });
const district = await this.districtRepository.findOneBy({
id: profile.registrationDistrictId,
});
const subDistrict = await this.subDistrict.findOneBy({ id: profile.registrationSubDistrictId });
const root = const root =
profile.current_holders == null || profile.current_holders == null ||
profile.current_holders.length == 0 || profile.current_holders.length == 0 ||
@ -147,22 +151,19 @@ export class ProfileController extends Controller {
DateOfBirth: profile.birthDate, DateOfBirth: profile.birthDate,
DateRetire: profile.dateRetire, DateRetire: profile.dateRetire,
RegistrationAddress: `${profile.registrationAddress}\r\nตำบล/แขวง ${province?.name}\r\nเขต/อำเภอ ${district?.name}\r\nจังหวัด ${subDistrict?.name} รหัสไปรษณีย์ ${profile.registrationZipCode}`, RegistrationAddress: `${profile.registrationAddress}\r\nตำบล/แขวง ${province?.name}\r\nเขต/อำเภอ ${district?.name}\r\nจังหวัด ${subDistrict?.name} รหัสไปรษณีย์ ${profile.registrationZipCode}`,
SalaryAmount: profile.profileSalary.length > 0 SalaryAmount:
? profile.profileSalary[0].amount.toString() profile.profileSalary.length > 0 ? profile.profileSalary[0].amount.toString() : null,
: null, Education:
Education: profile.profileEducations.length > 0 profile.profileEducations.length > 0
? profile.profileEducations[profile.profileEducations.length-1].institute ? profile.profileEducations[profile.profileEducations.length - 1].institute
: null, : null,
AppointText: profile.dateAppoint, AppointText: profile.dateAppoint,
SalaryDate: profile.profileSalary.length > 0 SalaryDate: profile.profileSalary.length > 0 ? profile.profileSalary[0].date : null,
? profile.profileSalary[0].date
: null,
PositionName: profile.position, PositionName: profile.position,
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`, OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
} };
return new HttpSuccess(mapData); return new HttpSuccess(mapData);
} }
/** /**
@ -945,7 +946,7 @@ export class ProfileController extends Controller {
"profile.citizenId", "profile.citizenId",
"profileSalary.position", "profileSalary.position",
"profileSalary.posNo", "profileSalary.posNo",
"profileSalary.date" "profileSalary.date",
]) ])
.andWhere( .andWhere(
requestBody.position != null && requestBody.position != "" && requestBody.posNo == undefined requestBody.position != null && requestBody.position != "" && requestBody.posNo == undefined
@ -965,27 +966,27 @@ export class ProfileController extends Controller {
) )
.getMany(); .getMany();
const mapData = profiles.map(profile => { const mapData = profiles.map((profile) => {
let profileSalary; let profileSalary;
if (profile.profileSalary && profile.profileSalary.length > 0) { if (profile.profileSalary && profile.profileSalary.length > 0) {
profileSalary = profile.profileSalary.reduce((latest, current) => { profileSalary = profile.profileSalary.reduce((latest, current) => {
return new Date(current.date) > new Date(latest.date) ? current : latest; return new Date(current.date) > new Date(latest.date) ? current : latest;
}); });
} }
return { return {
id: profile.id, id: profile.id,
// prefix: profile.prefix, // prefix: profile.prefix,
// firstName: profile.firstName, // firstName: profile.firstName,
// lastName: profile.lastName, // lastName: profile.lastName,
fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`, fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`,
citizenId: profile.citizenId, citizenId: profile.citizenId,
position: profileSalary ? profileSalary.position : null, position: profileSalary ? profileSalary.position : null,
posNo: profileSalary ? profileSalary.posNo : null, posNo: profileSalary ? profileSalary.posNo : null,
date: profileSalary ? profileSalary.date : null date: profileSalary ? profileSalary.date : null,
}; };
}); });
return new HttpSuccess(mapData); return new HttpSuccess(mapData);
} }
/** /**
@ -1061,6 +1062,8 @@ export class ProfileController extends Controller {
profileId: profile.id, profileId: profile.id,
prefix: profile.prefix, prefix: profile.prefix,
rank: profile.rank, rank: profile.rank,
avatar: profile.avatar,
avatarName: profile.avatarName,
firstName: profile.firstName, firstName: profile.firstName,
lastName: profile.lastName, lastName: profile.lastName,
citizenId: profile.citizenId, citizenId: profile.citizenId,