Merge branch 'develop' into adiDev
This commit is contained in:
commit
b32bff1456
6 changed files with 477 additions and 40 deletions
|
|
@ -1255,12 +1255,16 @@ export class CommandController extends Controller {
|
||||||
const postData = querystring.stringify(body);
|
const postData = querystring.stringify(body);
|
||||||
|
|
||||||
// get admin token
|
// get admin token
|
||||||
const response = await axios.post(`${process.env.KC_URL}/realms/${process.env.KC_REALM}/protocol/openid-connect/token`, postData, {
|
const response = await axios.post(
|
||||||
headers: {
|
`${process.env.KC_URL}/realms/${process.env.KC_REALM}/protocol/openid-connect/token`,
|
||||||
"Content-Type": "application/x-www-form-urlencoded",
|
postData,
|
||||||
api_key: process.env.API_KEY,
|
{
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
api_key: process.env.API_KEY,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
);
|
||||||
|
|
||||||
const adminToken = response.data.access_token;
|
const adminToken = response.data.access_token;
|
||||||
|
|
||||||
|
|
@ -1730,12 +1734,14 @@ export class CommandController extends Controller {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
commandRecive.amount = salaryData ? salaryData.amount : null_;
|
commandRecive.amount = salaryData ? salaryData.amount : null_;
|
||||||
|
commandRecive.amountSpecial = salaryData ? salaryData.amountSpecial : null_;
|
||||||
commandRecive.positionSalaryAmount = salaryData
|
commandRecive.positionSalaryAmount = salaryData
|
||||||
? salaryData.positionSalaryAmount
|
? salaryData.positionSalaryAmount
|
||||||
: null_;
|
: null_;
|
||||||
commandRecive.mouthSalaryAmount = salaryData ? salaryData.mouthSalaryAmount : null_;
|
commandRecive.mouthSalaryAmount = salaryData ? salaryData.mouthSalaryAmount : null_;
|
||||||
} else {
|
} else {
|
||||||
commandRecive.amount = null_;
|
commandRecive.amount = null_;
|
||||||
|
commandRecive.amountSpecial = null_;
|
||||||
commandRecive.positionSalaryAmount = null_;
|
commandRecive.positionSalaryAmount = null_;
|
||||||
commandRecive.mouthSalaryAmount = null_;
|
commandRecive.mouthSalaryAmount = null_;
|
||||||
}
|
}
|
||||||
|
|
@ -2564,6 +2570,7 @@ export class CommandController extends Controller {
|
||||||
body: {
|
body: {
|
||||||
data: {
|
data: {
|
||||||
profileId: string;
|
profileId: string;
|
||||||
|
profileType?: string | null;
|
||||||
date?: Date | null;
|
date?: Date | null;
|
||||||
refCommandNo?: string | null;
|
refCommandNo?: string | null;
|
||||||
salaryRef?: string | null;
|
salaryRef?: string | null;
|
||||||
|
|
@ -2584,8 +2591,396 @@ export class CommandController extends Controller {
|
||||||
) {
|
) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
body.data.map(async (item) => {
|
body.data.map(async (item) => {
|
||||||
const profile = await this.profileRepository.findOne({
|
if (item.profileType && item.profileType.trim().toUpperCase() == "OFFICER") {
|
||||||
relations: ["profileSalary", "posLevel", "posType", "current_holders", "roleKeycloaks"],
|
const profile = await this.profileRepository.findOne({
|
||||||
|
relations: [
|
||||||
|
"profileSalary",
|
||||||
|
"posLevel",
|
||||||
|
"posType",
|
||||||
|
"current_holders",
|
||||||
|
"current_holders.orgRoot",
|
||||||
|
"current_holders.orgChild1",
|
||||||
|
"current_holders.orgChild2",
|
||||||
|
"current_holders.orgChild3",
|
||||||
|
"current_holders.orgChild4",
|
||||||
|
"roleKeycloaks",
|
||||||
|
],
|
||||||
|
where: { id: item.profileId },
|
||||||
|
order: {
|
||||||
|
profileSalary: {
|
||||||
|
order: "DESC",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!profile) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
|
||||||
|
}
|
||||||
|
const orgRevision = await this.orgRevisionRepo.findOne({
|
||||||
|
where: {
|
||||||
|
orgRevisionIsCurrent: true,
|
||||||
|
orgRevisionIsDraft: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const shortName =
|
||||||
|
!profile.current_holders || profile.current_holders.length == 0
|
||||||
|
? null
|
||||||
|
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
|
||||||
|
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
|
||||||
|
?.orgChild4 != null
|
||||||
|
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
|
||||||
|
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
|
||||||
|
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
|
||||||
|
?.orgChild3 != null
|
||||||
|
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
|
||||||
|
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
|
||||||
|
null &&
|
||||||
|
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
|
||||||
|
?.orgChild2 != null
|
||||||
|
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
|
||||||
|
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
|
||||||
|
null &&
|
||||||
|
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
|
||||||
|
?.orgChild1 != null
|
||||||
|
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
|
||||||
|
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
|
||||||
|
null &&
|
||||||
|
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
|
||||||
|
?.orgRoot != null
|
||||||
|
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
|
||||||
|
: null;
|
||||||
|
let position =
|
||||||
|
profile.current_holders
|
||||||
|
.filter((x) => x.orgRevisionId == orgRevision?.id)[0]
|
||||||
|
?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null;
|
||||||
|
// ประวัติตำแหน่ง
|
||||||
|
const data = new ProfileSalary();
|
||||||
|
const meta = {
|
||||||
|
profileId: profile.id,
|
||||||
|
commandId: item.commandId,
|
||||||
|
date: item.date,
|
||||||
|
refCommandNo: item.refCommandNo,
|
||||||
|
templateDoc: item.salaryRef,
|
||||||
|
position: profile.position,
|
||||||
|
positionType: profile.posType.posTypeName,
|
||||||
|
positionLevel: profile.posLevel.posLevelName,
|
||||||
|
posNo: shortName ? shortName : "-",
|
||||||
|
positionLine: position?.positionField ?? "-",
|
||||||
|
positionPathSide: position?.positionArea ?? "-",
|
||||||
|
positionExecutive: position?.posExecutive?.posExecutiveName ?? "-",
|
||||||
|
amount: item.amount ? item.amount : 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,
|
||||||
|
createdUserId: req.user.sub,
|
||||||
|
createdFullName: req.user.name,
|
||||||
|
lastUpdateUserId: req.user.sub,
|
||||||
|
lastUpdateFullName: req.user.name,
|
||||||
|
createdAt: new Date(),
|
||||||
|
lastUpdatedAt: new Date(),
|
||||||
|
dateGovernment: new Date(),
|
||||||
|
isGovernment: item.isGovernment,
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.assign(data, meta);
|
||||||
|
const history = new ProfileSalaryHistory();
|
||||||
|
Object.assign(history, { ...data, id: undefined });
|
||||||
|
|
||||||
|
await this.salaryRepo.save(data);
|
||||||
|
history.profileSalaryId = data.id;
|
||||||
|
await this.salaryHistoryRepo.save(history);
|
||||||
|
|
||||||
|
// ประวัติวินัย
|
||||||
|
const dataDis = new ProfileDiscipline();
|
||||||
|
|
||||||
|
const metaDis = {
|
||||||
|
createdUserId: req.user.sub,
|
||||||
|
createdFullName: req.user.name,
|
||||||
|
lastUpdateUserId: req.user.sub,
|
||||||
|
lastUpdateFullName: req.user.name,
|
||||||
|
createdAt: new Date(),
|
||||||
|
lastUpdatedAt: new Date(),
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.assign(dataDis, { ...body, ...metaDis });
|
||||||
|
const historyDis = new ProfileDisciplineHistory();
|
||||||
|
Object.assign(historyDis, { ...dataDis, id: undefined });
|
||||||
|
|
||||||
|
await this.disciplineRepository.save(dataDis);
|
||||||
|
historyDis.profileDisciplineId = dataDis.id;
|
||||||
|
await this.disciplineHistoryRepository.save(historyDis);
|
||||||
|
|
||||||
|
// ทะเบียนประวัติ
|
||||||
|
if (item.isLeave != null) {
|
||||||
|
const _profile = await this.profileRepository.findOne({
|
||||||
|
where: { id: item.profileId },
|
||||||
|
});
|
||||||
|
if (!_profile) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
|
||||||
|
}
|
||||||
|
const _null: any = null;
|
||||||
|
_profile.isLeave = item.isLeave;
|
||||||
|
_profile.leaveReason = item.leaveReason ?? _null;
|
||||||
|
_profile.dateLeave = item.dateLeave ?? _null;
|
||||||
|
_profile.lastUpdateUserId = req.user.sub;
|
||||||
|
_profile.lastUpdateFullName = req.user.name;
|
||||||
|
_profile.lastUpdatedAt = new Date();
|
||||||
|
const exceptClear = await checkExceptCommandType(String(item.commandId));
|
||||||
|
if (item.isLeave == true && !exceptClear) {
|
||||||
|
await removeProfileInOrganize(_profile.id, "OFFICER");
|
||||||
|
}
|
||||||
|
//คำสั่งพักราชการ หรือ ให้ออกจากราชการไว้ก่อน solutionเดิม ให้ disable user ไว้แต่ยังไม่ลบ เปลี่ยนเป็นลบ user ออกเลย
|
||||||
|
else if (item.isLeave == true && exceptClear && _profile.keycloak != null) {
|
||||||
|
// const enableActive = await enableStatus(_profile.keycloak, false);
|
||||||
|
// if (!enableActive) throw new Error("Failed. Cannot change enable status.");
|
||||||
|
const delUserKeycloak = await deleteUser(_profile.keycloak);
|
||||||
|
if (delUserKeycloak) {
|
||||||
|
_profile.keycloak = _null;
|
||||||
|
_profile.roleKeycloaks = [];
|
||||||
|
_profile.isActive = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const clearProfile = await checkCommandType(String(item.commandId));
|
||||||
|
if (clearProfile) {
|
||||||
|
if (_profile.keycloak != null) {
|
||||||
|
const delUserKeycloak = await deleteUser(_profile.keycloak);
|
||||||
|
if (delUserKeycloak) {
|
||||||
|
_profile.keycloak = _null;
|
||||||
|
_profile.roleKeycloaks = [];
|
||||||
|
_profile.isActive = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_profile.position = _null;
|
||||||
|
_profile.posTypeId = _null;
|
||||||
|
_profile.posLevelId = _null;
|
||||||
|
}
|
||||||
|
await this.profileRepository.save(_profile);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const profile = await this.profileEmployeeRepository.findOne({
|
||||||
|
relations: [
|
||||||
|
"profileSalary",
|
||||||
|
"posLevel",
|
||||||
|
"posType",
|
||||||
|
"current_holders",
|
||||||
|
"current_holders.orgRoot",
|
||||||
|
"current_holders.orgChild1",
|
||||||
|
"current_holders.orgChild2",
|
||||||
|
"current_holders.orgChild3",
|
||||||
|
"current_holders.orgChild4",
|
||||||
|
"roleKeycloaks",
|
||||||
|
],
|
||||||
|
where: { id: item.profileId },
|
||||||
|
order: {
|
||||||
|
profileSalary: {
|
||||||
|
order: "DESC",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!profile) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
|
||||||
|
}
|
||||||
|
const orgRevision = await this.orgRevisionRepo.findOne({
|
||||||
|
where: {
|
||||||
|
orgRevisionIsCurrent: true,
|
||||||
|
orgRevisionIsDraft: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const shortName =
|
||||||
|
!profile.current_holders || profile.current_holders.length == 0
|
||||||
|
? null
|
||||||
|
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
|
||||||
|
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
|
||||||
|
?.orgChild4 != null
|
||||||
|
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
|
||||||
|
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
|
||||||
|
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
|
||||||
|
?.orgChild3 != null
|
||||||
|
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
|
||||||
|
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
|
||||||
|
null &&
|
||||||
|
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
|
||||||
|
?.orgChild2 != null
|
||||||
|
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
|
||||||
|
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
|
||||||
|
null &&
|
||||||
|
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
|
||||||
|
?.orgChild1 != null
|
||||||
|
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
|
||||||
|
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
|
||||||
|
null &&
|
||||||
|
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
|
||||||
|
?.orgRoot != null
|
||||||
|
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
|
||||||
|
: null;
|
||||||
|
// let position =
|
||||||
|
// profile.current_holders
|
||||||
|
// .filter((x) => x.orgRevisionId == orgRevision?.id)[0]
|
||||||
|
// ?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null;
|
||||||
|
// ประวัติตำแหน่ง
|
||||||
|
const data = new ProfileSalary();
|
||||||
|
const meta = {
|
||||||
|
profileEmployeeId: profile.id,
|
||||||
|
commandId: item.commandId,
|
||||||
|
date: item.date,
|
||||||
|
refCommandNo: item.refCommandNo,
|
||||||
|
templateDoc: item.salaryRef,
|
||||||
|
position: profile.position,
|
||||||
|
positionType: profile.posType.posTypeName,
|
||||||
|
positionLevel: profile.posLevel.posLevelName,
|
||||||
|
posNo: shortName ? shortName : "-",
|
||||||
|
// positionLine: position?.positionField ?? "-",
|
||||||
|
// positionPathSide: position?.positionArea ?? "-",
|
||||||
|
// positionExecutive: position?.posExecutive?.posExecutiveName ?? "-",
|
||||||
|
amount: item.amount ? item.amount : 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,
|
||||||
|
createdUserId: req.user.sub,
|
||||||
|
createdFullName: req.user.name,
|
||||||
|
lastUpdateUserId: req.user.sub,
|
||||||
|
lastUpdateFullName: req.user.name,
|
||||||
|
createdAt: new Date(),
|
||||||
|
lastUpdatedAt: new Date(),
|
||||||
|
dateGovernment: new Date(),
|
||||||
|
isGovernment: item.isGovernment,
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.assign(data, meta);
|
||||||
|
const history = new ProfileSalaryHistory();
|
||||||
|
Object.assign(history, { ...data, id: undefined });
|
||||||
|
|
||||||
|
await this.salaryRepo.save(data);
|
||||||
|
history.profileSalaryId = data.id;
|
||||||
|
await this.salaryHistoryRepo.save(history);
|
||||||
|
|
||||||
|
// ประวัติวินัย
|
||||||
|
const dataDis = new ProfileDiscipline();
|
||||||
|
|
||||||
|
const metaDis = {
|
||||||
|
createdUserId: req.user.sub,
|
||||||
|
createdFullName: req.user.name,
|
||||||
|
lastUpdateUserId: req.user.sub,
|
||||||
|
lastUpdateFullName: req.user.name,
|
||||||
|
createdAt: new Date(),
|
||||||
|
lastUpdatedAt: new Date(),
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.assign(dataDis, {
|
||||||
|
...body,
|
||||||
|
...metaDis,
|
||||||
|
profileEmployeeId: item.profileId,
|
||||||
|
profileId: undefined,
|
||||||
|
});
|
||||||
|
const historyDis = new ProfileDisciplineHistory();
|
||||||
|
Object.assign(historyDis, { ...dataDis, id: undefined });
|
||||||
|
|
||||||
|
await this.disciplineRepository.save(dataDis);
|
||||||
|
historyDis.profileDisciplineId = dataDis.id;
|
||||||
|
await this.disciplineHistoryRepository.save(historyDis);
|
||||||
|
|
||||||
|
// ทะเบียนประวัติ
|
||||||
|
if (item.isLeave != null) {
|
||||||
|
const _profile = await this.profileEmployeeRepository.findOne({
|
||||||
|
where: { id: item.profileId },
|
||||||
|
});
|
||||||
|
if (!_profile) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
|
||||||
|
}
|
||||||
|
const _null: any = null;
|
||||||
|
_profile.isLeave = item.isLeave;
|
||||||
|
_profile.leaveReason = item.leaveReason ?? _null;
|
||||||
|
_profile.dateLeave = item.dateLeave ?? _null;
|
||||||
|
_profile.lastUpdateUserId = req.user.sub;
|
||||||
|
_profile.lastUpdateFullName = req.user.name;
|
||||||
|
_profile.lastUpdatedAt = new Date();
|
||||||
|
const exceptClear = await checkExceptCommandType(String(item.commandId));
|
||||||
|
if (item.isLeave == true && !exceptClear) {
|
||||||
|
await removeProfileInOrganize(_profile.id, "EMPLOYEE");
|
||||||
|
}
|
||||||
|
//คำสั่งพักราชการ หรือ ให้ออกจากราชการไว้ก่อน solutionเดิม ให้ disable user ไว้แต่ยังไม่ลบ เปลี่ยนเป็นลบ user ออกเลย
|
||||||
|
else if (item.isLeave == true && exceptClear && _profile.keycloak != null) {
|
||||||
|
// const enableActive = await enableStatus(_profile.keycloak, false);
|
||||||
|
// if (!enableActive) throw new Error("Failed. Cannot change enable status.");
|
||||||
|
const delUserKeycloak = await deleteUser(_profile.keycloak);
|
||||||
|
if (delUserKeycloak) {
|
||||||
|
_profile.keycloak = _null;
|
||||||
|
_profile.roleKeycloaks = [];
|
||||||
|
_profile.isActive = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const clearProfile = await checkCommandType(String(item.commandId));
|
||||||
|
if (clearProfile) {
|
||||||
|
if (_profile.keycloak != null) {
|
||||||
|
const delUserKeycloak = await deleteUser(_profile.keycloak);
|
||||||
|
if (delUserKeycloak) {
|
||||||
|
_profile.keycloak = _null;
|
||||||
|
_profile.roleKeycloaks = [];
|
||||||
|
_profile.isActive = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_profile.position = _null;
|
||||||
|
_profile.posTypeId = _null;
|
||||||
|
_profile.posLevelId = _null;
|
||||||
|
}
|
||||||
|
await this.profileEmployeeRepository.save(_profile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post("excexute/salary-employee-leave-discipline")
|
||||||
|
public async newSalaryEmployeeAndUpdateLeaveDiscipline(
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Body()
|
||||||
|
body: {
|
||||||
|
data: {
|
||||||
|
profileId: string;
|
||||||
|
date?: Date | null;
|
||||||
|
refCommandNo?: string | null;
|
||||||
|
salaryRef?: string | null;
|
||||||
|
isLeave: boolean | null;
|
||||||
|
leaveReason?: string | null;
|
||||||
|
dateLeave?: Date | null;
|
||||||
|
refCommandDate?: Date | null;
|
||||||
|
detail?: string | null;
|
||||||
|
level?: string | null;
|
||||||
|
unStigma?: string | null;
|
||||||
|
commandId?: string | null;
|
||||||
|
amount?: Double | null;
|
||||||
|
positionSalaryAmount?: Double | null;
|
||||||
|
mouthSalaryAmount?: Double | null;
|
||||||
|
isGovernment?: boolean | null;
|
||||||
|
}[];
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
await Promise.all(
|
||||||
|
body.data.map(async (item) => {
|
||||||
|
const profile = await this.profileEmployeeRepository.findOne({
|
||||||
|
relations: [
|
||||||
|
"profileSalary",
|
||||||
|
"posLevel",
|
||||||
|
"posType",
|
||||||
|
"current_holders",
|
||||||
|
"current_holders.orgRoot",
|
||||||
|
"current_holders.orgChild1",
|
||||||
|
"current_holders.orgChild2",
|
||||||
|
"current_holders.orgChild3",
|
||||||
|
"current_holders.orgChild4",
|
||||||
|
"roleKeycloaks",
|
||||||
|
],
|
||||||
where: { id: item.profileId },
|
where: { id: item.profileId },
|
||||||
order: {
|
order: {
|
||||||
profileSalary: {
|
profileSalary: {
|
||||||
|
|
@ -2628,14 +3023,14 @@ export class CommandController extends Controller {
|
||||||
?.orgRoot != null
|
?.orgRoot != null
|
||||||
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
|
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`
|
||||||
: null;
|
: null;
|
||||||
let position =
|
// let position =
|
||||||
profile.current_holders
|
// profile.current_holders
|
||||||
.filter((x) => x.orgRevisionId == orgRevision?.id)[0]
|
// .filter((x) => x.orgRevisionId == orgRevision?.id)[0]
|
||||||
?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null;
|
// ?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null;
|
||||||
// ประวัติตำแหน่ง
|
// ประวัติตำแหน่ง
|
||||||
const data = new ProfileSalary();
|
const data = new ProfileSalary();
|
||||||
const meta = {
|
const meta = {
|
||||||
profileId: profile.id,
|
profileEmployeeId: profile.id,
|
||||||
commandId: item.commandId,
|
commandId: item.commandId,
|
||||||
date: item.date,
|
date: item.date,
|
||||||
refCommandNo: item.refCommandNo,
|
refCommandNo: item.refCommandNo,
|
||||||
|
|
@ -2644,9 +3039,9 @@ export class CommandController extends Controller {
|
||||||
positionType: profile.posType.posTypeName,
|
positionType: profile.posType.posTypeName,
|
||||||
positionLevel: profile.posLevel.posLevelName,
|
positionLevel: profile.posLevel.posLevelName,
|
||||||
posNo: shortName ? shortName : "-",
|
posNo: shortName ? shortName : "-",
|
||||||
positionLine: position?.positionField ?? "-",
|
// positionLine: position?.positionField ?? "-",
|
||||||
positionPathSide: position?.positionArea ?? "-",
|
// positionPathSide: position?.positionArea ?? "-",
|
||||||
positionExecutive: position?.posExecutive?.posExecutiveName ?? "-",
|
// positionExecutive: position?.posExecutive?.posExecutiveName ?? "-",
|
||||||
amount: item.amount ? item.amount : null,
|
amount: item.amount ? item.amount : 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,
|
||||||
|
|
@ -2686,7 +3081,12 @@ export class CommandController extends Controller {
|
||||||
lastUpdatedAt: new Date(),
|
lastUpdatedAt: new Date(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.assign(dataDis, { ...body, ...metaDis });
|
Object.assign(dataDis, {
|
||||||
|
...body,
|
||||||
|
...metaDis,
|
||||||
|
profileEmployeeId: item.profileId,
|
||||||
|
profileId: undefined,
|
||||||
|
});
|
||||||
const historyDis = new ProfileDisciplineHistory();
|
const historyDis = new ProfileDisciplineHistory();
|
||||||
Object.assign(historyDis, { ...dataDis, id: undefined });
|
Object.assign(historyDis, { ...dataDis, id: undefined });
|
||||||
|
|
||||||
|
|
@ -2696,7 +3096,7 @@ export class CommandController extends Controller {
|
||||||
|
|
||||||
// ทะเบียนประวัติ
|
// ทะเบียนประวัติ
|
||||||
if (item.isLeave != null) {
|
if (item.isLeave != null) {
|
||||||
const _profile = await this.profileRepository.findOne({
|
const _profile = await this.profileEmployeeRepository.findOne({
|
||||||
where: { id: item.profileId },
|
where: { id: item.profileId },
|
||||||
});
|
});
|
||||||
if (!_profile) {
|
if (!_profile) {
|
||||||
|
|
@ -2711,7 +3111,7 @@ export class CommandController extends Controller {
|
||||||
_profile.lastUpdatedAt = new Date();
|
_profile.lastUpdatedAt = new Date();
|
||||||
const exceptClear = await checkExceptCommandType(String(item.commandId));
|
const exceptClear = await checkExceptCommandType(String(item.commandId));
|
||||||
if (item.isLeave == true && !exceptClear) {
|
if (item.isLeave == true && !exceptClear) {
|
||||||
await removeProfileInOrganize(_profile.id, "OFFICER");
|
await removeProfileInOrganize(_profile.id, "EMPLOYEE");
|
||||||
}
|
}
|
||||||
//คำสั่งพักราชการ หรือ ให้ออกจากราชการไว้ก่อน solutionเดิม ให้ disable user ไว้แต่ยังไม่ลบ เปลี่ยนเป็นลบ user ออกเลย
|
//คำสั่งพักราชการ หรือ ให้ออกจากราชการไว้ก่อน solutionเดิม ให้ disable user ไว้แต่ยังไม่ลบ เปลี่ยนเป็นลบ user ออกเลย
|
||||||
else if (item.isLeave == true && exceptClear && _profile.keycloak != null) {
|
else if (item.isLeave == true && exceptClear && _profile.keycloak != null) {
|
||||||
|
|
@ -2738,7 +3138,7 @@ export class CommandController extends Controller {
|
||||||
_profile.posTypeId = _null;
|
_profile.posTypeId = _null;
|
||||||
_profile.posLevelId = _null;
|
_profile.posLevelId = _null;
|
||||||
}
|
}
|
||||||
await this.profileRepository.save(_profile);
|
await this.profileEmployeeRepository.save(_profile);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
@ -2908,6 +3308,11 @@ export class CommandController extends Controller {
|
||||||
"posType",
|
"posType",
|
||||||
"posLevel",
|
"posLevel",
|
||||||
"current_holders",
|
"current_holders",
|
||||||
|
"current_holders.orgRoot",
|
||||||
|
"current_holders.orgChild1",
|
||||||
|
"current_holders.orgChild2",
|
||||||
|
"current_holders.orgChild3",
|
||||||
|
"current_holders.orgChild4",
|
||||||
"current_holders.positions",
|
"current_holders.positions",
|
||||||
"current_holders.positions.posExecutive",
|
"current_holders.positions.posExecutive",
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -4863,6 +4863,7 @@ export class ProfileController extends Controller {
|
||||||
node: null,
|
node: null,
|
||||||
nodeId: null,
|
nodeId: null,
|
||||||
salary: profile ? profile.amount : null,
|
salary: profile ? profile.amount : null,
|
||||||
|
amountSpecial: profile ? profile.amountSpecial : null
|
||||||
};
|
};
|
||||||
|
|
||||||
if (_profile.child4Id != null) {
|
if (_profile.child4Id != null) {
|
||||||
|
|
|
||||||
|
|
@ -172,7 +172,7 @@ export class ProfileDevelopmentController extends Controller {
|
||||||
summary: null,
|
summary: null,
|
||||||
point: null,
|
point: null,
|
||||||
name: data.name,
|
name: data.name,
|
||||||
achievement10: "มีผลการพัฒนาและมีการดำเนินการตามเป้าหมายการนำไปพัฒนางาน1",
|
achievement10: "มีผลการพัฒนาและมีการดำเนินการตามเป้าหมายการนำไปพัฒนางาน",
|
||||||
achievement5: "มีผลการพัฒนาแต่ยังไม่ได้ดำเนินการตามเป้าหมายการนำไปพัฒนางาน",
|
achievement5: "มีผลการพัฒนาแต่ยังไม่ได้ดำเนินการตามเป้าหมายการนำไปพัฒนางาน",
|
||||||
achievement0: "ไม่ได้ดำเนินการพัฒนา",
|
achievement0: "ไม่ได้ดำเนินการพัฒนา",
|
||||||
isDevelopment70: data.isDevelopment70,
|
isDevelopment70: data.isDevelopment70,
|
||||||
|
|
|
||||||
|
|
@ -2064,7 +2064,8 @@ export class ProfileEmployeeController extends Controller {
|
||||||
child4ShortName: child4 == null ? null : child4.orgChild4ShortName,
|
child4ShortName: child4 == null ? null : child4.orgChild4ShortName,
|
||||||
node: null,
|
node: null,
|
||||||
nodeId: null,
|
nodeId: null,
|
||||||
salary: profile.amount,
|
salary: profile ? profile.amount : null,
|
||||||
|
amountSpecial: profile ? profile.amountSpecial : null
|
||||||
};
|
};
|
||||||
return new HttpSuccess(_profile);
|
return new HttpSuccess(_profile);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1866,7 +1866,8 @@ export class ProfileEmployeeTempController extends Controller {
|
||||||
? null
|
? null
|
||||||
: profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild4
|
: profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild4
|
||||||
.orgChild4Name,
|
.orgChild4Name,
|
||||||
salary: profile.amount,
|
salary: profile ? profile.amount : null,
|
||||||
|
amountSpecial: profile ? profile.amountSpecial : null
|
||||||
};
|
};
|
||||||
return new HttpSuccess(_profile);
|
return new HttpSuccess(_profile);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
import { NextFunction, Request, Response } from "express";
|
import { NextFunction, Request, Response } from "express";
|
||||||
import { Client } from "@elastic/elasticsearch";
|
import { Client } from "@elastic/elasticsearch";
|
||||||
import permission from "../interfaces/permission";
|
import { AppDataSource } from "../database/data-source";
|
||||||
|
import { PosMaster } from "../entities/PosMaster";
|
||||||
|
import { OrgRevision } from "../entities/OrgRevision";
|
||||||
|
import { Profile } from "../entities/Profile";
|
||||||
|
|
||||||
if (!process.env.ELASTICSEARCH_INDEX) {
|
if (!process.env.ELASTICSEARCH_INDEX) {
|
||||||
throw new Error("Require ELASTICSEARCH_INDEX to store log.");
|
throw new Error("Require ELASTICSEARCH_INDEX to store log.");
|
||||||
|
|
@ -19,48 +22,74 @@ const LOG_LEVEL_MAP: Record<string, number> = {
|
||||||
const elasticsearch = new Client({
|
const elasticsearch = new Client({
|
||||||
node: `${process.env.ELASTICSEARCH_PROTOCOL}://${process.env.ELASTICSEARCH_HOST}:${process.env.ELASTICSEARCH_PORT}`,
|
node: `${process.env.ELASTICSEARCH_PROTOCOL}://${process.env.ELASTICSEARCH_HOST}:${process.env.ELASTICSEARCH_PORT}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
async function logMiddleware(req: Request, res: Response, next: NextFunction) {
|
async function logMiddleware(req: Request, res: Response, next: NextFunction) {
|
||||||
if (!req.url.startsWith("/api/")) return next();
|
if (!req.url.startsWith("/api/")) return next();
|
||||||
|
|
||||||
let data: any;
|
let data: any;
|
||||||
|
const repoPosmaster = AppDataSource.getRepository(PosMaster);
|
||||||
|
const repoProfile = AppDataSource.getRepository(Profile);
|
||||||
|
const repoRevision = AppDataSource.getRepository(OrgRevision);
|
||||||
|
|
||||||
const originalJson = res.json;
|
const originalJson = res.json;
|
||||||
|
|
||||||
res.json = function (v: any) {
|
res.json = function (v: any) {
|
||||||
data = v;
|
data = v;
|
||||||
return originalJson.call(this, v);
|
return originalJson.call(this, v);
|
||||||
};
|
};
|
||||||
|
|
||||||
const timestamp = new Date().toISOString();
|
const timestamp = new Date().toISOString();
|
||||||
const start = performance.now();
|
const start = performance.now();
|
||||||
|
|
||||||
req.app.locals.logData = {};
|
req.app.locals.logData = {};
|
||||||
|
|
||||||
|
const revision = await repoRevision.findOne({
|
||||||
|
where: {
|
||||||
|
orgRevisionIsCurrent: true,
|
||||||
|
orgRevisionIsDraft: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
res.on("finish", async () => {
|
res.on("finish", async () => {
|
||||||
try {
|
try {
|
||||||
if (!req.url.startsWith("/api/")) return;
|
if (!req.url.startsWith("/api/")) return;
|
||||||
|
let system = "organization";
|
||||||
|
if (req.url.startsWith("/api/v1/org/keycloak/log/sso")) system = "inout";
|
||||||
|
if (req.url.startsWith("/api/v1/org/metadata/")) system = "master";
|
||||||
|
if (req.url.startsWith("/api/v1/org/pos/position/")) system = "master";
|
||||||
|
if (req.url.startsWith("/api/v1/org/pos/type/")) system = "master";
|
||||||
|
if (req.url.startsWith("/api/v1/org/employee/pos/position/")) system = "master";
|
||||||
|
if (req.url.startsWith("/api/v1/org/employee/pos/type/")) system = "master";
|
||||||
|
if (req.url.startsWith("/api/v1/org/auth/authRoleAttr/")) system = "admin";
|
||||||
|
if (req.url.startsWith("/api/v1/org/auth/authRole/")) system = "admin";
|
||||||
|
// if (req.url.startsWith("/api/v1/org/keycloak")) system = "admin";
|
||||||
|
if (req.url.startsWith("/api/v1/org/pos/admin/master/list")) system = "admin";
|
||||||
|
if (req.url.startsWith("/api/v1/org/super-admin/{id}")) system = "admin";
|
||||||
|
if (req.url.startsWith("/api/v1/org/permission-org/")) system = "admin";
|
||||||
|
if (req.url.startsWith("/api/v1/org/pos/assign/")) system = "admin";
|
||||||
|
if (req.url.startsWith("/api/v1/org/profile/")) system = "registry";
|
||||||
|
if (req.url.startsWith("/api/v1/org/profile-employee/")) system = "registry";
|
||||||
|
if (req.url.startsWith("/api/v1/org/profile-temp/")) system = "registry";
|
||||||
|
|
||||||
const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "debug"] || 4;
|
const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "debug"] || 4;
|
||||||
|
const profileByKeycloak = await repoProfile.findOne({
|
||||||
|
where: { keycloak: req.app.locals.logData.userId },
|
||||||
|
});
|
||||||
|
const rootId = await repoPosmaster.findOne({
|
||||||
|
where: {
|
||||||
|
current_holderId: profileByKeycloak?.id,
|
||||||
|
orgRevisionId: revision?.id,
|
||||||
|
},
|
||||||
|
select: ["orgRootId"],
|
||||||
|
});
|
||||||
|
|
||||||
if (level === 1 && res.statusCode < 500) return;
|
if (level === 1 && res.statusCode < 500) return;
|
||||||
if (level === 2 && res.statusCode < 400) return;
|
if (level === 2 && res.statusCode < 400) return;
|
||||||
if (level === 3 && res.statusCode < 200) return;
|
if (level === 3 && res.statusCode < 200) return;
|
||||||
|
|
||||||
const token = req.headers["authorization"];
|
|
||||||
let rootId = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
rootId = token
|
|
||||||
? await new permission().checkOrg(token, req.app.locals.logData.userId)
|
|
||||||
: null;
|
|
||||||
} catch (err) {
|
|
||||||
console.warn("Error fetching rootId:", err);
|
|
||||||
}
|
|
||||||
|
|
||||||
const obj = {
|
const obj = {
|
||||||
logType: res.statusCode >= 500 ? "error" : res.statusCode >= 400 ? "warning" : "info",
|
logType: res.statusCode >= 500 ? "error" : res.statusCode >= 400 ? "warning" : "info",
|
||||||
ip: req.ip,
|
ip: req.ip,
|
||||||
rootId: rootId?.orgRootId ?? null,
|
rootId: rootId?.orgRootId ?? null,
|
||||||
systemName: "evaluation",
|
systemName: system,
|
||||||
startTimeStamp: timestamp,
|
startTimeStamp: timestamp,
|
||||||
endTimeStamp: new Date().toISOString(),
|
endTimeStamp: new Date().toISOString(),
|
||||||
processTime: performance.now() - start,
|
processTime: performance.now() - start,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue