fix ข้อมูลตำแหน่ง-เงินเดือน (หน่วยงานที่ออกคำสั่งไม่แสดง) #1394

This commit is contained in:
Bright 2025-04-25 15:06:54 +07:00
parent d4f745c61f
commit 921e23f81a
3 changed files with 245 additions and 9 deletions

View file

@ -2952,6 +2952,22 @@ export class CommandController extends Controller {
}[];
},
) {
let _posNumCodeSit: string = ""
const _command = await this.commandRepository.findOne({
where: { id: body.data.find(x => x.commandId)?.commandId ?? "" }
});
if (_command) {
if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร"
else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร"
else {
let _profileAdmin = await this.profileRepository.findOne({
where: { keycloak: _command?.createdUserId.toString()},
relations: ["current_holders", "current_holders.orgRoot",]
});
_posNumCodeSit = _profileAdmin?.current_holders
.find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? ""
}
}
await Promise.all(
body.data.map(async (item) => {
const profile: any = await this.profileRepository.findOneBy({ id: item.profileId });
@ -2975,7 +2991,7 @@ export class CommandController extends Controller {
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
data.posNumCodeSit = _posNumCodeSit;
Object.assign(data, { ...item, ...meta });
const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined });
@ -3084,6 +3100,22 @@ export class CommandController extends Controller {
}[];
},
) {
let _posNumCodeSit: string = ""
const _command = await this.commandRepository.findOne({
where: { id: body.data.find(x => x.commandId)?.commandId ?? "" }
});
if (_command) {
if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร"
else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร"
else {
let _profileAdmin = await this.profileRepository.findOne({
where: { keycloak: _command?.createdUserId.toString()},
relations: ["current_holders", "current_holders.orgRoot",]
});
_posNumCodeSit = _profileAdmin?.current_holders
.find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? ""
}
}
await Promise.all(
body.data.map(async (item) => {
const profile: any = await this.profileEmployeeRepository.findOneBy({ id: item.profileId });
@ -3097,7 +3129,7 @@ export class CommandController extends Controller {
});
const before = null;
const data = new ProfileSalary();
data.posNumCodeSit = _posNumCodeSit;
const meta = {
order: dest_item == null ? 1 : dest_item.order + 1,
createdUserId: req.user.sub,
@ -3235,6 +3267,22 @@ export class CommandController extends Controller {
const roleKeycloak = await this.roleKeycloakRepo.findOne({
where: { name: Like("USER") },
});
let _posNumCodeSit: string = ""
const _command = await this.commandRepository.findOne({
where: { id: body.data.find(x => x.commandId)?.commandId ?? "" }
});
if (_command) {
if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร"
else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร"
else {
let _profileAdmin = await this.profileRepository.findOne({
where: { keycloak: _command?.createdUserId.toString()},
relations: ["current_holders", "current_holders.orgRoot",]
});
_posNumCodeSit = _profileAdmin?.current_holders
.find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? ""
}
}
await Promise.all(
body.data.map(async (item) => {
const profile = await this.profileRepository.findOne({
@ -3261,7 +3309,7 @@ export class CommandController extends Controller {
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
data.posNumCodeSit = _posNumCodeSit;
Object.assign(data, { ...item, ...meta });
const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined });
@ -3408,6 +3456,22 @@ export class CommandController extends Controller {
}[];
},
) {
let _posNumCodeSit: string = ""
const _command = await this.commandRepository.findOne({
where: { id: body.data.find(x => x.commandId)?.commandId ?? "" }
});
if (_command) {
if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร"
else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร"
else {
let _profileAdmin = await this.profileRepository.findOne({
where: { keycloak: _command?.createdUserId.toString()},
relations: ["current_holders", "current_holders.orgRoot",]
});
_posNumCodeSit = _profileAdmin?.current_holders
.find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? ""
}
}
await Promise.all(
body.data.map(async (item) => {
const profile = await this.profileEmployeeRepository.findOne({
@ -3424,7 +3488,7 @@ export class CommandController extends Controller {
});
const before = null;
const data = new ProfileSalary();
data.posNumCodeSit = _posNumCodeSit;
const meta = {
order: dest_item == null ? 1 : dest_item.order + 1,
createdUserId: req.user.sub,
@ -3525,6 +3589,22 @@ export class CommandController extends Controller {
}[];
},
) {
let _posNumCodeSit: string = ""
const _command = await this.commandRepository.findOne({
where: { id: body.data.find(x => x.commandId)?.commandId ?? "" }
});
if (_command) {
if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร"
else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร"
else {
let _profileAdmin = await this.profileRepository.findOne({
where: { keycloak: _command?.createdUserId.toString()},
relations: ["current_holders", "current_holders.orgRoot",]
});
_posNumCodeSit = _profileAdmin?.current_holders
.find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? ""
}
}
await Promise.all(
body.data.map(async (item) => {
const profile: any = await this.profileRepository.findOne({
@ -3541,7 +3621,7 @@ export class CommandController extends Controller {
});
const before = null;
const data = new ProfileSalary();
data.posNumCodeSit = _posNumCodeSit;
const meta = {
order: dest_item == null ? 1 : dest_item.order + 1,
createdUserId: req.user.sub,
@ -3790,6 +3870,22 @@ export class CommandController extends Controller {
}[];
},
) {
let _posNumCodeSit: string = ""
const _command = await this.commandRepository.findOne({
where: { id: body.data.find(x => x.commandId)?.commandId ?? "" }
});
if (_command) {
if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร"
else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร"
else {
let _profileAdmin = await this.profileRepository.findOne({
where: { keycloak: _command?.createdUserId.toString()},
relations: ["current_holders", "current_holders.orgRoot",]
});
_posNumCodeSit = _profileAdmin?.current_holders
.find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? ""
}
}
await Promise.all(
body.data.map(async (item) => {
if (item.profileType && item.profileType.trim().toUpperCase() == "OFFICER") {
@ -3863,6 +3959,7 @@ export class CommandController extends Controller {
?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null;
// ประวัติตำแหน่ง
const data = new ProfileSalary();
data.posNumCodeSit = _posNumCodeSit;
const meta = {
profileId: profile.id,
commandId: item.commandId,
@ -4056,6 +4153,7 @@ export class CommandController extends Controller {
// ?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null;
// ประวัติตำแหน่ง
const data = new ProfileSalary();
data.posNumCodeSit = _posNumCodeSit;
const meta = {
profileEmployeeId: profile.id,
commandId: item.commandId,
@ -4224,6 +4322,22 @@ export class CommandController extends Controller {
}[];
},
) {
let _posNumCodeSit: string = ""
const _command = await this.commandRepository.findOne({
where: { id: body.data.find(x => x.commandId)?.commandId ?? "" }
});
if (_command) {
if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร"
else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร"
else {
let _profileAdmin = await this.profileRepository.findOne({
where: { keycloak: _command?.createdUserId.toString()},
relations: ["current_holders", "current_holders.orgRoot",]
});
_posNumCodeSit = _profileAdmin?.current_holders
.find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? ""
}
}
await Promise.all(
body.data.map(async (item) => {
const profile = await this.profileEmployeeRepository.findOne({
@ -4295,6 +4409,7 @@ export class CommandController extends Controller {
// ?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null;
// ประวัติตำแหน่ง
const data = new ProfileSalary();
data.posNumCodeSit = _posNumCodeSit;
const meta = {
profileEmployeeId: profile.id,
commandId: item.commandId,
@ -4451,6 +4566,22 @@ export class CommandController extends Controller {
}[];
},
) {
let _posNumCodeSit: string = ""
const _command = await this.commandRepository.findOne({
where: { id: body.data.find(x => x.commandId)?.commandId ?? "" }
});
if (_command) {
if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร"
else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร"
else {
let _profileAdmin = await this.profileRepository.findOne({
where: { keycloak: _command?.createdUserId.toString()},
relations: ["current_holders", "current_holders.orgRoot",]
});
_posNumCodeSit = _profileAdmin?.current_holders
.find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? ""
}
}
await Promise.all(
body.data.map(async (item) => {
const profile = await this.profileRepository.findOne({
@ -4523,6 +4654,7 @@ export class CommandController extends Controller {
?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null;
// ประวัติตำแหน่ง
const data = new ProfileSalary();
data.posNumCodeSit = _posNumCodeSit;
const meta = {
profileId: item.profileId,
commandId: item.commandId,
@ -4610,6 +4742,22 @@ export class CommandController extends Controller {
}[];
},
) {
let _posNumCodeSit: string = ""
const _command = await this.commandRepository.findOne({
where: { id: body.data.find(x => x.commandId)?.commandId ?? "" }
});
if (_command) {
if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร"
else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร"
else {
let _profileAdmin = await this.profileRepository.findOne({
where: { keycloak: _command?.createdUserId.toString()},
relations: ["current_holders", "current_holders.orgRoot",]
});
_posNumCodeSit = _profileAdmin?.current_holders
.find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? ""
}
}
await Promise.all(
body.data.map(async (item) => {
const profile = await this.profileRepository.findOne({
@ -4735,6 +4883,7 @@ export class CommandController extends Controller {
commandCode: item.commandCode,
commandName: item.commandName,
remark: item.remark,
posNumCodeSit: _posNumCodeSit
});
await removeProfileInOrganize(profile.id, "OFFICER");
const clearProfile = await checkCommandType(String(item.commandId));
@ -4816,6 +4965,24 @@ export class CommandController extends Controller {
const list = await getRoles();
if (!Array.isArray(list)) throw new Error("Failed. Cannot get role(s) data from the server.");
const _null: any = null;
let _posNumCodeSit: string = ""
const _command = await this.commandRepository.findOne({
where: {
id: body.data.find(x => x.bodySalarys?.commandId)?.bodySalarys?.commandId ?? ""
}
});
if (_command) {
if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร"
else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร"
else {
let _profileAdmin = await this.profileRepository.findOne({
where: { keycloak: _command?.createdUserId.toString()},
relations: ["current_holders", "current_holders.orgRoot",]
});
_posNumCodeSit = _profileAdmin?.current_holders
.find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? ""
}
}
await Promise.all(
body.data.map(async (item) => {
const before = null;
@ -5106,6 +5273,7 @@ export class CommandController extends Controller {
order: { order: "DESC" },
});
const profileSal: any = new ProfileSalary();
profileSal.posNumCodeSit = _posNumCodeSit;
Object.assign(profileSal, { ...item.bodySalarys, ...meta });
const salaryHistory = new ProfileSalaryHistory();
Object.assign(salaryHistory, { ...profileSal, id: undefined });
@ -5276,6 +5444,22 @@ export class CommandController extends Controller {
const roleKeycloak = await this.roleKeycloakRepo.findOne({
where: { name: Like("USER") },
});
let _posNumCodeSit: string = ""
const _command = await this.commandRepository.findOne({
where: { id: body.refIds.find(x => x.commandId)?.commandId ?? "" }
});
if (_command) {
if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร"
else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร"
else {
let _profileAdmin = await this.profileRepository.findOne({
where: { keycloak: _command?.createdUserId.toString()},
relations: ["current_holders", "current_holders.orgRoot",]
});
_posNumCodeSit = _profileAdmin?.current_holders
.find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? ""
}
}
await Promise.all(
body.refIds.map(async (item) => {
const profile = await this.profileEmployeeRepository.findOne({
@ -5325,7 +5509,7 @@ export class CommandController extends Controller {
});
const before = null;
const data = new ProfileSalary();
data.posNumCodeSit = _posNumCodeSit;
const meta = {
profileEmployeeId: profile.id,
amount: item.amount,
@ -5782,6 +5966,22 @@ export class CommandController extends Controller {
}[];
},
) {
let _posNumCodeSit: string = ""
const _command = await this.commandRepository.findOne({
where: { id: body.refIds.find(x => x.commandId)?.commandId ?? "" }
});
if (_command) {
if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร"
else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร"
else {
let _profileAdmin = await this.profileRepository.findOne({
where: { keycloak: _command?.createdUserId.toString()},
relations: ["current_holders", "current_holders.orgRoot",]
});
_posNumCodeSit = _profileAdmin?.current_holders
.find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? ""
}
}
await Promise.all(
body.refIds.map(async (item) => {
const posMaster = await this.posMasterRepository.findOne({
@ -5834,7 +6034,7 @@ export class CommandController extends Controller {
});
const before = null;
const data = new ProfileSalary();
data.posNumCodeSit = _posNumCodeSit;
const meta = {
profileId: profile?.id,
date: new Date(),