api ข้อมูลตำแหน่งและเงินเดือน (ใช้ในรายงานประวัติสำหรับการเสนอขอพระราชทานเหรียญจักรพรรดิมาลา)

This commit is contained in:
Bright 2025-08-25 18:59:33 +07:00
parent f05e2fef55
commit 5678f333db

View file

@ -26,6 +26,8 @@ import { Profile } from "../entities/Profile";
import { Insignia } from "../entities/Insignia";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
import { ProfileSalary } from "../entities/ProfileSalary";
import { In, IsNull } from "typeorm";
@Route("api/v1/org/profile/insignia")
@Tags("ProfileInsignia")
@Security("bearerAuth")
@ -34,6 +36,7 @@ export class ProfileInsigniaController extends Controller {
private insigniaRepo = AppDataSource.getRepository(ProfileInsignia);
private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory);
private insigniaMetaRepo = AppDataSource.getRepository(Insignia);
private profileSalaryRepo = AppDataSource.getRepository(ProfileSalary);
@Get("user")
public async getInsigniaUser(@Request() request: { user: Record<string, any> }) {
@ -258,4 +261,75 @@ export class ProfileInsigniaController extends Controller {
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);
}
}