Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2024-06-25 18:42:05 +07:00
commit d5373fb62b
10 changed files with 897 additions and 209 deletions

View file

@ -901,6 +901,9 @@ export class ProfileController extends Controller {
}
const profile: Profile = Object.assign(new Profile(), body);
const _null: any = null;
profile.dateRetire = body.birthDate == null ? _null : calculateRetireDate(body.birthDate);
profile.dateRetireLaw = body.birthDate == null ? _null : calculateRetireLaw(body.birthDate);
profile.createdUserId = request.user.sub;
profile.createdFullName = request.user.name;
profile.lastUpdateUserId = request.user.sub;
@ -2516,7 +2519,7 @@ export class ProfileController extends Controller {
root: root == null ? null : root.orgRootName,
orgRootShortName: root == null ? null : root.orgRootShortName,
orgRevisionId: root == null ? null : root.orgRevisionId,
org: `${_child4}${_child3}${_child2}${_child1}${root?.orgRootName}`,
org: `${_child4}${_child3}${_child2}${_child1}${root?.orgRootName ?? ""}`,
};
}),
);
@ -2968,18 +2971,23 @@ export class ProfileController extends Controller {
if (_profile.child4Id != null) {
_profile.node = 4;
_profile.nodeId = _profile.child4Id;
_profile.nodeShortName = _profile.child4ShortName;
} else if (_profile.child3Id != null) {
_profile.node = 3;
_profile.nodeId = _profile.child3Id;
_profile.nodeShortName = _profile.child3ShortName;
} else if (_profile.child2Id != null) {
_profile.node = 2;
_profile.nodeId = _profile.child2Id;
_profile.nodeShortName = _profile.child2ShortName;
} else if (_profile.child1Id != null) {
_profile.node = 1;
_profile.nodeId = _profile.child1Id;
_profile.nodeShortName = _profile.child1ShortName;
} else if (_profile.rootId != null) {
_profile.node = 0;
_profile.nodeId = _profile.rootId;
_profile.nodeShortName = _profile.rootShortName;
}
return new HttpSuccess(_profile);
}
@ -3695,6 +3703,7 @@ export class ProfileController extends Controller {
keyword?: string;
},
) {
const isProbation: boolean = true;
const [findProfile, total] = await AppDataSource.getRepository(Profile)
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.posLevel", "posLevel")
@ -3708,12 +3717,24 @@ export class ProfileController extends Controller {
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.leftJoinAndSelect("current_holders.positions", "positions")
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
.where("profile.prefix LIKE :keyword", { keyword: `%${body.keyword}%` })
.orWhere("profile.firstName LIKE :keyword", { keyword: `%${body.keyword}%` })
.orWhere("profile.lastName LIKE :keyword", { keyword: `%${body.keyword}%` })
.orWhere("profile.position LIKE :keyword", { keyword: `%${body.keyword}%` })
.orWhere("posLevel.posLevelName LIKE :keyword", { keyword: `%${body.keyword}%` })
.orWhere("posType.posTypeName LIKE :keyword", { keyword: `%${body.keyword}%` })
.where(`profile.prefix LIKE :keyword and profile.isProbation = ${isProbation}`, {
keyword: `%${body.keyword}%`,
})
.orWhere(`profile.firstName LIKE :keyword and profile.isProbation = ${isProbation}`, {
keyword: `%${body.keyword}%`,
})
.orWhere(`profile.lastName LIKE :keyword and profile.isProbation = ${isProbation}`, {
keyword: `%${body.keyword}%`,
})
.orWhere(`profile.position LIKE :keyword and profile.isProbation = ${isProbation}`, {
keyword: `%${body.keyword}%`,
})
.orWhere(`posLevel.posLevelName LIKE :keyword and profile.isProbation = ${isProbation}`, {
keyword: `%${body.keyword}%`,
})
.orWhere(`posType.posTypeName LIKE :keyword and profile.isProbation = ${isProbation}`, {
keyword: `%${body.keyword}%`,
})
.orderBy("profile.citizenId", "ASC")
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
@ -4423,17 +4444,25 @@ export class ProfileController extends Controller {
async updateLeaveUser(
@Path() id: string,
@Body()
requestBody: { isLeave: boolean; leaveReason: string; dateLeave: Date },
requestBody: { isLeave: boolean; leaveReason?: any; dateLeave?: any },
@Request() request: { user: Record<string, any> },
) {
const profile = await this.profileRepo.findOne({
where: { id: id },
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const _null: any = null;
profile.isLeave = requestBody.isLeave;
profile.leaveReason = requestBody.leaveReason;
profile.dateLeave = requestBody.dateLeave;
if (requestBody.leaveReason != undefined && requestBody.leaveReason != null) {
profile.leaveReason = requestBody.leaveReason;
} else {
profile.leaveReason = _null;
}
if (requestBody.dateLeave != undefined && requestBody.dateLeave != null) {
profile.dateLeave = requestBody.dateLeave;
} else {
profile.dateLeave = _null;
}
await this.profileRepo.save(profile);
const profileSalary = await this.salaryRepository.findOne({
@ -4645,7 +4674,7 @@ export class ProfileController extends Controller {
return new HttpSuccess(profile);
}
/**
/**
* API
*
* @summary ORG_065 - (ADMIN) #XXX
@ -4656,96 +4685,194 @@ export class ProfileController extends Controller {
@Request() request: RequestWithUser,
@Body() body: CreateProfileAllFields,
) {
const citizen = await this.profileRepo.findOne({
where: { citizenId: body.citizenId },
select: ["id"],
});
if (citizen) return new HttpSuccess(citizen.id);
const _null: any = null;
const profile: Profile = Object.assign(new Profile(), body);
if (body && body.posLevelId) {
const findPosLevel = await this.posLevelRepo.findOne({
where: { posLevelName: body.posLevelId },
select:['id','posLevelName']
select: ["id", "posLevelName"],
});
if (findPosLevel) {
profile.posLevelId = findPosLevel.id;
} else {
profile.posLevelId = _null;
}
} else {
profile.posLevelId = _null;
}
if (body && body.posTypeId) {
const findPosType = await this.posTypeRepo.findOne({
where: { posTypeName: body.posTypeId },
select:['id','posTypeName']
select: ["id", "posTypeName"],
});
if (findPosType) {
profile.posTypeId = findPosType.id;
} else {
profile.posTypeId = _null;
}
} else {
profile.posTypeId = _null;
}
if (body && body.prefix) {
const findPrefix = await this.prefixRepo.findOne({
where: { name: body.prefix },
select:['id','name']
});
if (findPrefix) {
profile.prefix = findPrefix.id;
}
}
// if (body && body.prefix) {
// const findPrefix = await this.prefixRepo.findOne({
// where: { name: body.prefix },
// select: ["id", "name"],
// });
// if (findPrefix) {
// profile.prefix = findPrefix.id;
// } else {
// profile.prefix = _null;
// }
// } else {
// profile.prefix = _null;
// }
//current
if (body && body.currentProvinceId) {
const findProvince = await this.provinceRepo.findOne({
where: { name: body.currentProvinceId },
select:['id','name']
select: ["id", "name"],
});
if (findProvince) {
profile.currentProvinceId = findProvince.id;
}
if (findProvince) {
profile.currentProvinceId = findProvince.id;
} else {
profile.currentProvinceId = _null;
}
} else {
profile.currentProvinceId = _null;
}
if (body && body.currentDistrictId) {
const findDistrict = await this.districtRepo.findOne({
where: { name: body.currentDistrictId },
select:['id','name']
select: ["id", "name"],
});
if (findDistrict) {
profile.currentDistrictId = findDistrict.id;
}
if (findDistrict) {
profile.currentDistrictId = findDistrict.id;
} else {
profile.currentDistrictId = _null;
}
} else {
profile.currentDistrictId = _null;
}
if (body && body.currentSubDistrictId) {
const findSubDistrict = await this.subDistrictRepo.findOne({
where: { name: body.currentSubDistrictId },
select:['id','name']
select: ["id", "name"],
});
if (findSubDistrict) {
profile.currentSubDistrictId = findSubDistrict.id;
} else {
profile.currentSubDistrictId = _null;
}
} else {
profile.currentSubDistrictId = _null;
}
//register
if (body && body.registrationProvinceId) {
const findProvince_regis = await this.provinceRepo.findOne({
where: { name: body.registrationProvinceId },
select:['id','name']
select: ["id", "name"],
});
if (findProvince_regis) {
profile.registrationProvinceId = findProvince_regis.id;
} else {
profile.registrationProvinceId = _null;
}
} else {
profile.registrationProvinceId = _null;
}
if (body && body.registrationDistrictId) {
const findDistrict_regis = await this.districtRepo.findOne({
where: { name: body.registrationDistrictId },
select:['id','name']
select: ["id", "name"],
});
if (findDistrict_regis) {
profile.registrationDistrictId = findDistrict_regis.id;
} else {
profile.registrationDistrictId = _null;
}
} else {
profile.registrationDistrictId = _null;
}
if (body && body.registrationSubDistrictId) {
const findSubDistrict_regis = await this.subDistrictRepo.findOne({
where: { name: body.registrationSubDistrictId },
select:['id','name']
select: ["id", "name"],
});
if (findSubDistrict_regis) {
profile.registrationSubDistrictId = findSubDistrict_regis.id;
}
if (findSubDistrict_regis) {
profile.registrationSubDistrictId = findSubDistrict_regis.id;
} else {
profile.registrationSubDistrictId = _null;
}
} else {
profile.registrationSubDistrictId = _null;
}
profile.createdUserId = request.user.sub;
profile.createdFullName = request.user.name;
profile.lastUpdateUserId = request.user.sub;
profile.lastUpdateFullName = request.user.name;
// return new HttpSuccess(profile);
await this.profileRepo.save(profile);
return new HttpSuccess(profile.id);
}
/**
*
* @summary (ADMIN)
*
*/
@Get("retireDate/mock")
async calRetireDate() {
const profile = await this.profileRepo.find({ relations: ["profileSalary"] });
const _null: any = null;
const profiles = profile.map((_data) => ({
..._data,
dateRetire: _data.birthDate == null ? _null : calculateRetireDate(_data.birthDate),
dateRetireLaw: _data.birthDate == null ? _null : calculateRetireLaw(_data.birthDate),
}));
await this.profileRepo.save(profiles);
return new HttpSuccess();
}
/**
*
* @summary (ADMIN)
*
*/
@Get("salarym/ock")
async calSalaryDate() {
const profile = await this.profileRepo.find();
const _null: any = null;
const profiles = await Promise.all(
profile.map(async (_data) => {
const salary = await this.salaryRepository.findOne({
where: {
profileId: _data.id,
},
order: { order: "DESC" },
});
const type = await this.posTypeRepo.findOne({
where: {
posTypeName: salary?.positionType ?? "",
},
});
const level = await this.posLevelRepo.findOne({
where: {
posLevelName: salary?.positionLevel ?? "",
},
});
return {
..._data,
position: salary?.position ?? _null,
posLevelId: level?.id ?? _null,
posTypeId: type?.id ?? _null,
};
}),
);
await this.profileRepo.save(profiles);
return new HttpSuccess("zxczx");
}
}