อัปเดตจำนวนสิทธิ์การลาเมื่อผ่านทดลองงานฯ #2304
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m19s

This commit is contained in:
harid 2026-02-12 18:31:24 +07:00
parent d555c70af9
commit 9a1acc0b7d
2 changed files with 112 additions and 28 deletions

View file

@ -99,6 +99,7 @@ import {
CreatePosMasterHistoryOfficer, CreatePosMasterHistoryOfficer,
} from "../services/PositionService"; } from "../services/PositionService";
import { PostRetireToExprofile } from "./ExRetirementController"; import { PostRetireToExprofile } from "./ExRetirementController";
import { LeaveType } from "../entities/LeaveType"
@Route("api/v1/org/command") @Route("api/v1/org/command")
@Tags("Command") @Tags("Command")
@Security("bearerAuth") @Security("bearerAuth")
@ -154,7 +155,7 @@ export class CommandController extends Controller {
private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory); private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory);
private genderRepo = AppDataSource.getRepository(Gender); private genderRepo = AppDataSource.getRepository(Gender);
private avatarRepository = AppDataSource.getRepository(ProfileAvatar); private avatarRepository = AppDataSource.getRepository(ProfileAvatar);
private leaveType = AppDataSource.getRepository(LeaveType);
/** /**
* API list * API list
* *
@ -5766,10 +5767,15 @@ export class CommandController extends Controller {
) { ) {
let _posNumCodeSit: string = ""; let _posNumCodeSit: string = "";
let _posNumCodeSitAbb: string = ""; let _posNumCodeSitAbb: string = "";
let commandType: any = ""
const _command = await this.commandRepository.findOne({ const _command = await this.commandRepository.findOne({
where: { id: body.data.find((x) => x.commandId)?.commandId ?? "" }, where: { id: body.data.find((x) => x.commandId)?.commandId ?? "" },
}); });
if (_command) { if (_command) {
commandType = await this.commandTypeRepository.findOne({
select: { code: true },
where: { id: _command.commandTypeId }
});
if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") { if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") {
const orgRootDeputy = await this.orgRootRepository.findOne({ const orgRootDeputy = await this.orgRootRepository.findOne({
where: { where: {
@ -5807,11 +5813,15 @@ export class CommandController extends Controller {
.orgRootShortName ?? ""; .orgRootShortName ?? "";
} }
} }
const leaveType = await this.leaveType.findOne({
select:{ id: true, limit: true, code: true },
where:{ code: "LV-005" }
});
await Promise.all( await Promise.all(
body.data.map(async (item) => { body.data.map(async (item) => {
const profile = await this.profileRepository.findOne({ const profile = await this.profileRepository.findOne({
relations: [ relations: [
"profileSalary", // "profileSalary",
"posType", "posType",
"posLevel", "posLevel",
"current_holders", "current_holders",
@ -5822,16 +5832,21 @@ export class CommandController extends Controller {
"current_holders.orgChild4", "current_holders.orgChild4",
], ],
where: { id: item.profileId }, where: { id: item.profileId },
order: { // order: {
profileSalary: { // profileSalary: {
order: "DESC", // order: "DESC",
}, // },
}, // },
}); });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
} }
const lastSalary = await this.salaryRepo.findOne({
where: { profileId: item.profileId },
select: ["order"],
order: { order: "DESC" },
});
const nextOrder = lastSalary ? lastSalary.order + 1 : 1;
const orgRevision = await this.orgRevisionRepo.findOne({ const orgRevision = await this.orgRevisionRepo.findOne({
where: { where: {
orgRevisionIsCurrent: true, orgRevisionIsCurrent: true,
@ -5892,12 +5907,13 @@ export class CommandController extends Controller {
amountSpecial: item.amountSpecial ? item.amountSpecial : null, amountSpecial: item.amountSpecial ? item.amountSpecial : null,
positionSalaryAmount: item.positionSalaryAmount ? item.positionSalaryAmount : null, positionSalaryAmount: item.positionSalaryAmount ? item.positionSalaryAmount : null,
mouthSalaryAmount: item.mouthSalaryAmount ? item.mouthSalaryAmount : null, mouthSalaryAmount: item.mouthSalaryAmount ? item.mouthSalaryAmount : null,
order: // order:
profile.profileSalary.length >= 0 // profile.profileSalary.length >= 0
? profile.profileSalary.length > 0 // ? profile.profileSalary.length > 0
? profile.profileSalary[0].order + 1 // ? profile.profileSalary[0].order + 1
: 1 // : 1
: null, // : null,
order: nextOrder,
orgRoot: orgRootRef?.orgRootName ?? null, orgRoot: orgRootRef?.orgRootName ?? null,
orgChild1: orgChild1Ref?.orgChild1Name ?? null, orgChild1: orgChild1Ref?.orgChild1Name ?? null,
orgChild2: orgChild2Ref?.orgChild2Name ?? null, orgChild2: orgChild2Ref?.orgChild2Name ?? null,
@ -5928,19 +5944,41 @@ export class CommandController extends Controller {
await this.salaryHistoryRepo.save(history); await this.salaryHistoryRepo.save(history);
}), }),
); );
const checkCommandType = await this.commandRepository.findOne({ // const checkCommandType = await this.commandRepository.findOne({
where: { id: body.data.length > 0 ? body.data[0].commandId?.toString() : "" }, // where: { id: body.data.length > 0 ? body.data[0].commandId?.toString() : "" },
relations: ["commandType"], // relations: ["commandType"],
}); // });
if (checkCommandType?.commandType.code == "C-PM-11") { if (commandType && String(commandType.code) == "C-PM-11") {
const profile = await this.profileRepository.find({ // const profile = await this.profileRepository.find({
where: { id: In(body.data.map((x) => x.profileId)) }, // where: { id: In(body.data.map((x) => x.profileId)) },
}); // });
const data = profile.map((x) => ({ // const data = profile.map((x) => ({
...x, // ...x,
isProbation: false, // isProbation: false,
})); // }));
await this.profileRepository.save(data); // await this.profileRepository.save(data);
const profileIds = body.data.map((x) => x.profileId);
await this.profileRepository.update(
{ id: In(profileIds) },
{ isProbation: false }
);
// Task #2304 อัปเดตจำนวนสิทธิ์การลา เมื่อผ่านทดลองงานฯ
if (leaveType != null) {
await Promise.all(
body.data.map((item) =>
new CallAPI().PutData(req, `/leave-beginning/schedule`, {
profileId: item.profileId,
leaveTypeId: leaveType.id,
leaveYear: item.commandYear,
leaveDays: leaveType.limit,
leaveDaysUsed: 0,
leaveCount: 0,
beginningLeaveDays: 0,
beginningLeaveCount: 0,
})
)
);
}
} }
return new HttpSuccess(); return new HttpSuccess();
} }
@ -6461,7 +6499,7 @@ export class CommandController extends Controller {
await this.salaryHistoryRepo.save(history, { data: req }); await this.salaryHistoryRepo.save(history, { data: req });
if (profileEmployee.profileInsignias.length > 0) { if (profileEmployee.profileInsignias.length > 0) {
_oldInsigniaIds = profileEmployee.profileInsignias.map((x: any) => x.id); _oldInsigniaIds = profileEmployee.profileInsignias.filter().map((x: any) => x.id);
} }
await removeProfileInOrganize(profileEmployee.id, "EMPLOYEE"); await removeProfileInOrganize(profileEmployee.id, "EMPLOYEE");
if (profileEmployee.keycloak != null) { if (profileEmployee.keycloak != null) {

View file

@ -100,6 +100,52 @@ class CallAPI {
} }
} }
// Put
public async PutData(request: any, @Path() path: any, sendData: any, log = true) {
const token = "Bearer " + request.headers.authorization.replace("Bearer ", "");
const url = process.env.API_URL + path;
try {
const response = await axios.put(url, sendData, {
headers: {
Authorization: `${token}`,
"Content-Type": "application/json",
api_key: process.env.API_KEY,
},
});
if (log)
addLogSequence(request, {
action: "request",
status: "success",
description: "connected",
request: {
method: "PUT",
url: url,
payload: JSON.stringify(sendData),
response: JSON.stringify(response.data.result),
},
});
return response.data.result;
} catch (error) {
if (log)
addLogSequence(request, {
action: "request",
status: "error",
description: "unconnected",
request: {
method: "PUT",
url: url,
payload: JSON.stringify(sendData),
response: JSON.stringify(error),
},
});
throw error;
}
}
//Delete File //Delete File
public async DeleteFile(request: any, @Path() path: any) { public async DeleteFile(request: any, @Path() path: any) {
const token = "Bearer " + request.headers.authorization.replace("Bearer ", ""); const token = "Bearer " + request.headers.authorization.replace("Bearer ", "");