อัปเดตจำนวนสิทธิ์การลาเมื่อผ่านทดลองงานฯ #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,
} from "../services/PositionService";
import { PostRetireToExprofile } from "./ExRetirementController";
import { LeaveType } from "../entities/LeaveType"
@Route("api/v1/org/command")
@Tags("Command")
@Security("bearerAuth")
@ -154,7 +155,7 @@ export class CommandController extends Controller {
private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory);
private genderRepo = AppDataSource.getRepository(Gender);
private avatarRepository = AppDataSource.getRepository(ProfileAvatar);
private leaveType = AppDataSource.getRepository(LeaveType);
/**
* API list
*
@ -5766,10 +5767,15 @@ export class CommandController extends Controller {
) {
let _posNumCodeSit: string = "";
let _posNumCodeSitAbb: string = "";
let commandType: any = ""
const _command = await this.commandRepository.findOne({
where: { id: body.data.find((x) => x.commandId)?.commandId ?? "" },
});
if (_command) {
commandType = await this.commandTypeRepository.findOne({
select: { code: true },
where: { id: _command.commandTypeId }
});
if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") {
const orgRootDeputy = await this.orgRootRepository.findOne({
where: {
@ -5807,11 +5813,15 @@ export class CommandController extends Controller {
.orgRootShortName ?? "";
}
}
const leaveType = await this.leaveType.findOne({
select:{ id: true, limit: true, code: true },
where:{ code: "LV-005" }
});
await Promise.all(
body.data.map(async (item) => {
const profile = await this.profileRepository.findOne({
relations: [
"profileSalary",
// "profileSalary",
"posType",
"posLevel",
"current_holders",
@ -5822,16 +5832,21 @@ export class CommandController extends Controller {
"current_holders.orgChild4",
],
where: { id: item.profileId },
order: {
profileSalary: {
order: "DESC",
},
},
// order: {
// profileSalary: {
// order: "DESC",
// },
// },
});
if (!profile) {
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({
where: {
orgRevisionIsCurrent: true,
@ -5892,12 +5907,13 @@ export class CommandController extends Controller {
amountSpecial: item.amountSpecial ? item.amountSpecial : null,
positionSalaryAmount: item.positionSalaryAmount ? item.positionSalaryAmount : null,
mouthSalaryAmount: item.mouthSalaryAmount ? item.mouthSalaryAmount : null,
order:
profile.profileSalary.length >= 0
? profile.profileSalary.length > 0
? profile.profileSalary[0].order + 1
: 1
: null,
// order:
// profile.profileSalary.length >= 0
// ? profile.profileSalary.length > 0
// ? profile.profileSalary[0].order + 1
// : 1
// : null,
order: nextOrder,
orgRoot: orgRootRef?.orgRootName ?? null,
orgChild1: orgChild1Ref?.orgChild1Name ?? null,
orgChild2: orgChild2Ref?.orgChild2Name ?? null,
@ -5928,19 +5944,41 @@ export class CommandController extends Controller {
await this.salaryHistoryRepo.save(history);
}),
);
const checkCommandType = await this.commandRepository.findOne({
where: { id: body.data.length > 0 ? body.data[0].commandId?.toString() : "" },
relations: ["commandType"],
});
if (checkCommandType?.commandType.code == "C-PM-11") {
const profile = await this.profileRepository.find({
where: { id: In(body.data.map((x) => x.profileId)) },
});
const data = profile.map((x) => ({
...x,
isProbation: false,
}));
await this.profileRepository.save(data);
// const checkCommandType = await this.commandRepository.findOne({
// where: { id: body.data.length > 0 ? body.data[0].commandId?.toString() : "" },
// relations: ["commandType"],
// });
if (commandType && String(commandType.code) == "C-PM-11") {
// const profile = await this.profileRepository.find({
// where: { id: In(body.data.map((x) => x.profileId)) },
// });
// const data = profile.map((x) => ({
// ...x,
// isProbation: false,
// }));
// 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();
}
@ -6461,7 +6499,7 @@ export class CommandController extends Controller {
await this.salaryHistoryRepo.save(history, { data: req });
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");
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
public async DeleteFile(request: any, @Path() path: any) {
const token = "Bearer " + request.headers.authorization.replace("Bearer ", "");