api ข้อมูลตำแหน่งและเงินเดือน (ใช้ในรายงานประวัติสำหรับการเสนอขอพระราชทานเหรียญจักรพรรดิมาลา)
This commit is contained in:
parent
f05e2fef55
commit
5678f333db
1 changed files with 74 additions and 0 deletions
|
|
@ -26,6 +26,8 @@ import { Profile } from "../entities/Profile";
|
||||||
import { Insignia } from "../entities/Insignia";
|
import { Insignia } from "../entities/Insignia";
|
||||||
import permission from "../interfaces/permission";
|
import permission from "../interfaces/permission";
|
||||||
import { setLogDataDiff } from "../interfaces/utils";
|
import { setLogDataDiff } from "../interfaces/utils";
|
||||||
|
import { ProfileSalary } from "../entities/ProfileSalary";
|
||||||
|
import { In, IsNull } from "typeorm";
|
||||||
@Route("api/v1/org/profile/insignia")
|
@Route("api/v1/org/profile/insignia")
|
||||||
@Tags("ProfileInsignia")
|
@Tags("ProfileInsignia")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
|
|
@ -34,6 +36,7 @@ export class ProfileInsigniaController extends Controller {
|
||||||
private insigniaRepo = AppDataSource.getRepository(ProfileInsignia);
|
private insigniaRepo = AppDataSource.getRepository(ProfileInsignia);
|
||||||
private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory);
|
private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory);
|
||||||
private insigniaMetaRepo = AppDataSource.getRepository(Insignia);
|
private insigniaMetaRepo = AppDataSource.getRepository(Insignia);
|
||||||
|
private profileSalaryRepo = AppDataSource.getRepository(ProfileSalary);
|
||||||
|
|
||||||
@Get("user")
|
@Get("user")
|
||||||
public async getInsigniaUser(@Request() request: { user: Record<string, any> }) {
|
public async getInsigniaUser(@Request() request: { user: Record<string, any> }) {
|
||||||
|
|
@ -258,4 +261,75 @@ export class ProfileInsigniaController extends Controller {
|
||||||
|
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary ข้อมูลตำแหน่งและเงินเดือน (ใช้ในรายงานประวัติสำหรับการเสนอขอพระราชทานเหรียญจักรพรรดิมาลา)
|
||||||
|
*/
|
||||||
|
@Post("position")
|
||||||
|
public async GetPprofileSalarys(
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Body() body: { profileId: string },
|
||||||
|
) {
|
||||||
|
const profile = await this.profileRepo.findOneBy({ id: body.profileId });
|
||||||
|
if (!profile) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
|
}
|
||||||
|
const profileSalarys = await this.profileSalaryRepo.find({
|
||||||
|
where: [
|
||||||
|
{
|
||||||
|
profileId: body.profileId,
|
||||||
|
commandCode: In([
|
||||||
|
"0",
|
||||||
|
"9",
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"3",
|
||||||
|
"4",
|
||||||
|
"8",
|
||||||
|
"10",
|
||||||
|
"11",
|
||||||
|
"12",
|
||||||
|
"13",
|
||||||
|
"14",
|
||||||
|
"15",
|
||||||
|
"16",
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
{ profileId: body.profileId, commandCode: IsNull() },
|
||||||
|
],
|
||||||
|
order: { order: "ASC" },
|
||||||
|
});
|
||||||
|
if (!profileSalarys) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบข้อมูลตำแหน่งและเงินเดือน");
|
||||||
|
}
|
||||||
|
const birth = new Date(profile.birthDate);
|
||||||
|
const mapData = profileSalarys.map(x => {
|
||||||
|
// คำนวณอายุ
|
||||||
|
let age = null;
|
||||||
|
if (x.commandDateAffect && profile.birthDate) {
|
||||||
|
const affect = new Date(x.commandDateAffect);
|
||||||
|
age = affect.getFullYear() - birth.getFullYear();
|
||||||
|
// เช็คเดือน/วัน ถ้าวันเกิดยังไม่มาถึงในปีนั้น ให้ลบ 1
|
||||||
|
const monthDiff = affect.getMonth() - birth.getMonth();
|
||||||
|
const dayDiff = affect.getDate() - birth.getDate();
|
||||||
|
if (monthDiff < 0 || (monthDiff === 0 && dayDiff < 0)) {
|
||||||
|
age--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
dateAffect: x.commandDateAffect,
|
||||||
|
position: x.positionName,
|
||||||
|
root: x.orgRoot,
|
||||||
|
child1: x.orgChild1,
|
||||||
|
child2: x.orgChild2,
|
||||||
|
child3: x.orgChild3,
|
||||||
|
child4: x.orgChild4,
|
||||||
|
age: age,
|
||||||
|
amount: x.amount,
|
||||||
|
remark: x.remark,
|
||||||
|
commandCode: x.commandCode
|
||||||
|
};
|
||||||
|
});
|
||||||
|
return new HttpSuccess(mapData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue