Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2025-04-28 14:46:16 +07:00
commit 519de90743
6 changed files with 1748 additions and 81 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( await Promise.all(
body.data.map(async (item) => { body.data.map(async (item) => {
const profile: any = await this.profileRepository.findOneBy({ id: item.profileId }); const profile: any = await this.profileRepository.findOneBy({ id: item.profileId });
@ -2975,7 +2991,7 @@ export class CommandController extends Controller {
createdAt: new Date(), createdAt: new Date(),
lastUpdatedAt: new Date(), lastUpdatedAt: new Date(),
}; };
data.posNumCodeSit = _posNumCodeSit;
Object.assign(data, { ...item, ...meta }); Object.assign(data, { ...item, ...meta });
const history = new ProfileSalaryHistory(); const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined }); 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( await Promise.all(
body.data.map(async (item) => { body.data.map(async (item) => {
const profile: any = await this.profileEmployeeRepository.findOneBy({ id: item.profileId }); const profile: any = await this.profileEmployeeRepository.findOneBy({ id: item.profileId });
@ -3097,7 +3129,7 @@ export class CommandController extends Controller {
}); });
const before = null; const before = null;
const data = new ProfileSalary(); const data = new ProfileSalary();
data.posNumCodeSit = _posNumCodeSit;
const meta = { const meta = {
order: dest_item == null ? 1 : dest_item.order + 1, order: dest_item == null ? 1 : dest_item.order + 1,
createdUserId: req.user.sub, createdUserId: req.user.sub,
@ -3235,6 +3267,22 @@ export class CommandController extends Controller {
const roleKeycloak = await this.roleKeycloakRepo.findOne({ const roleKeycloak = await this.roleKeycloakRepo.findOne({
where: { name: Like("USER") }, 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( 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({
@ -3261,7 +3309,7 @@ export class CommandController extends Controller {
createdAt: new Date(), createdAt: new Date(),
lastUpdatedAt: new Date(), lastUpdatedAt: new Date(),
}; };
data.posNumCodeSit = _posNumCodeSit;
Object.assign(data, { ...item, ...meta }); Object.assign(data, { ...item, ...meta });
const history = new ProfileSalaryHistory(); const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined }); 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( await Promise.all(
body.data.map(async (item) => { body.data.map(async (item) => {
const profile = await this.profileEmployeeRepository.findOne({ const profile = await this.profileEmployeeRepository.findOne({
@ -3424,7 +3488,7 @@ export class CommandController extends Controller {
}); });
const before = null; const before = null;
const data = new ProfileSalary(); const data = new ProfileSalary();
data.posNumCodeSit = _posNumCodeSit;
const meta = { const meta = {
order: dest_item == null ? 1 : dest_item.order + 1, order: dest_item == null ? 1 : dest_item.order + 1,
createdUserId: req.user.sub, 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( await Promise.all(
body.data.map(async (item) => { body.data.map(async (item) => {
const profile: any = await this.profileRepository.findOne({ const profile: any = await this.profileRepository.findOne({
@ -3541,7 +3621,7 @@ export class CommandController extends Controller {
}); });
const before = null; const before = null;
const data = new ProfileSalary(); const data = new ProfileSalary();
data.posNumCodeSit = _posNumCodeSit;
const meta = { const meta = {
order: dest_item == null ? 1 : dest_item.order + 1, order: dest_item == null ? 1 : dest_item.order + 1,
createdUserId: req.user.sub, 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( await Promise.all(
body.data.map(async (item) => { body.data.map(async (item) => {
if (item.profileType && item.profileType.trim().toUpperCase() == "OFFICER") { 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; ?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null;
// ประวัติตำแหน่ง // ประวัติตำแหน่ง
const data = new ProfileSalary(); const data = new ProfileSalary();
data.posNumCodeSit = _posNumCodeSit;
const meta = { const meta = {
profileId: profile.id, profileId: profile.id,
commandId: item.commandId, commandId: item.commandId,
@ -4056,6 +4153,7 @@ export class CommandController extends Controller {
// ?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null; // ?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null;
// ประวัติตำแหน่ง // ประวัติตำแหน่ง
const data = new ProfileSalary(); const data = new ProfileSalary();
data.posNumCodeSit = _posNumCodeSit;
const meta = { const meta = {
profileEmployeeId: profile.id, profileEmployeeId: profile.id,
commandId: item.commandId, 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( await Promise.all(
body.data.map(async (item) => { body.data.map(async (item) => {
const profile = await this.profileEmployeeRepository.findOne({ const profile = await this.profileEmployeeRepository.findOne({
@ -4295,6 +4409,7 @@ export class CommandController extends Controller {
// ?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null; // ?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null;
// ประวัติตำแหน่ง // ประวัติตำแหน่ง
const data = new ProfileSalary(); const data = new ProfileSalary();
data.posNumCodeSit = _posNumCodeSit;
const meta = { const meta = {
profileEmployeeId: profile.id, profileEmployeeId: profile.id,
commandId: item.commandId, 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( 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({
@ -4523,6 +4654,7 @@ export class CommandController extends Controller {
?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null; ?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null;
// ประวัติตำแหน่ง // ประวัติตำแหน่ง
const data = new ProfileSalary(); const data = new ProfileSalary();
data.posNumCodeSit = _posNumCodeSit;
const meta = { const meta = {
profileId: item.profileId, profileId: item.profileId,
commandId: item.commandId, 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( 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({
@ -4735,6 +4883,7 @@ export class CommandController extends Controller {
commandCode: item.commandCode, commandCode: item.commandCode,
commandName: item.commandName, commandName: item.commandName,
remark: item.remark, remark: item.remark,
posNumCodeSit: _posNumCodeSit
}); });
await removeProfileInOrganize(profile.id, "OFFICER"); await removeProfileInOrganize(profile.id, "OFFICER");
const clearProfile = await checkCommandType(String(item.commandId)); const clearProfile = await checkCommandType(String(item.commandId));
@ -4816,6 +4965,24 @@ export class CommandController extends Controller {
const list = await getRoles(); const list = await getRoles();
if (!Array.isArray(list)) throw new Error("Failed. Cannot get role(s) data from the server."); if (!Array.isArray(list)) throw new Error("Failed. Cannot get role(s) data from the server.");
const _null: any = null; 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( await Promise.all(
body.data.map(async (item) => { body.data.map(async (item) => {
const before = null; const before = null;
@ -5106,6 +5273,7 @@ export class CommandController extends Controller {
order: { order: "DESC" }, order: { order: "DESC" },
}); });
const profileSal: any = new ProfileSalary(); const profileSal: any = new ProfileSalary();
profileSal.posNumCodeSit = _posNumCodeSit;
Object.assign(profileSal, { ...item.bodySalarys, ...meta }); Object.assign(profileSal, { ...item.bodySalarys, ...meta });
const salaryHistory = new ProfileSalaryHistory(); const salaryHistory = new ProfileSalaryHistory();
Object.assign(salaryHistory, { ...profileSal, id: undefined }); Object.assign(salaryHistory, { ...profileSal, id: undefined });
@ -5276,6 +5444,22 @@ export class CommandController extends Controller {
const roleKeycloak = await this.roleKeycloakRepo.findOne({ const roleKeycloak = await this.roleKeycloakRepo.findOne({
where: { name: Like("USER") }, 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( await Promise.all(
body.refIds.map(async (item) => { body.refIds.map(async (item) => {
const profile = await this.profileEmployeeRepository.findOne({ const profile = await this.profileEmployeeRepository.findOne({
@ -5325,7 +5509,7 @@ export class CommandController extends Controller {
}); });
const before = null; const before = null;
const data = new ProfileSalary(); const data = new ProfileSalary();
data.posNumCodeSit = _posNumCodeSit;
const meta = { const meta = {
profileEmployeeId: profile.id, profileEmployeeId: profile.id,
amount: item.amount, 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( await Promise.all(
body.refIds.map(async (item) => { body.refIds.map(async (item) => {
const posMaster = await this.posMasterRepository.findOne({ const posMaster = await this.posMasterRepository.findOne({
@ -5834,7 +6034,7 @@ export class CommandController extends Controller {
}); });
const before = null; const before = null;
const data = new ProfileSalary(); const data = new ProfileSalary();
data.posNumCodeSit = _posNumCodeSit;
const meta = { const meta = {
profileId: profile?.id, profileId: profile?.id,
date: new Date(), date: new Date(),

View file

@ -924,6 +924,12 @@ export class ProfileController extends Controller {
"registrationDistrict", "registrationDistrict",
"registrationProvince", "registrationProvince",
"profileAvatars", "profileAvatars",
"current_holders",
"current_holders.orgRoot",
"current_holders.orgChild1",
"current_holders.orgChild2",
"current_holders.orgChild3",
"current_holders.orgChild4",
], ],
order: { order: {
profileAvatars: { createdAt: "ASC" }, profileAvatars: { createdAt: "ASC" },
@ -934,13 +940,6 @@ export class ProfileController extends Controller {
let ImgUrl: any = null; let ImgUrl: any = null;
let _ImgUrl: any = []; let _ImgUrl: any = [];
if (profiles?.avatar != null && profiles?.avatarName != null) { if (profiles?.avatar != null && profiles?.avatarName != null) {
// await new CallAPI()
// .GetData(req, `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`)
// .then(async (x) => {
// ImgUrl = x.downloadUrl;
// })
// .catch();
let req_: any = req; let req_: any = req;
const token_ = "Bearer " + req_.headers.authorization.replace("Bearer ", ""); const token_ = "Bearer " + req_.headers.authorization.replace("Bearer ", "");
@ -975,18 +974,7 @@ export class ProfileController extends Controller {
ImgUrl = response_.data.downloadUrl; ImgUrl = response_.data.downloadUrl;
} catch {} } catch {}
} }
const profileOc = await this.profileRepo.findOne({
relations: [
"current_holders",
"current_holders.orgRoot",
"current_holders.orgChild1",
"current_holders.orgChild2",
"current_holders.orgChild3",
"current_holders.orgChild4",
],
where: { id: id },
});
if (!profileOc) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const orgRevision = await this.orgRevisionRepo.findOne({ const orgRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true }, where: { orgRevisionIsCurrent: true },
}); });
@ -1010,39 +998,39 @@ export class ProfileController extends Controller {
}); });
const root = const root =
profileOc.current_holders == null || profiles.current_holders == null ||
profileOc.current_holders.length == 0 || profiles.current_holders.length == 0 ||
profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null ? null
: profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot; : profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot;
const child1 = const child1 =
profileOc.current_holders == null || profiles.current_holders == null ||
profileOc.current_holders.length == 0 || profiles.current_holders.length == 0 ||
profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null ? null
: profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1; : profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1;
const child2 = const child2 =
profileOc.current_holders == null || profiles.current_holders == null ||
profileOc.current_holders.length == 0 || profiles.current_holders.length == 0 ||
profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null ? null
: profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2; : profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2;
const child3 = const child3 =
profileOc.current_holders == null || profiles.current_holders == null ||
profileOc.current_holders.length == 0 || profiles.current_holders.length == 0 ||
profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null ? null
: profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3; : profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3;
const child4 = const child4 =
profileOc.current_holders == null || profiles.current_holders == null ||
profileOc.current_holders.length == 0 || profiles.current_holders.length == 0 ||
profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null ? null
: profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4; : profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4;
// Construct org path // Construct org path
let _root = root?.orgRootName; let _root = root?.orgRootName;
@ -1058,7 +1046,7 @@ export class ProfileController extends Controller {
}); });
const certs = const certs =
cert_raw.length > 0 cert_raw.length > 0
? cert_raw.slice(-2).map((item) => ({ ? cert_raw.map((item) => ({
certificateType: item.certificateType ?? null, certificateType: item.certificateType ?? null,
issuer: item.issuer ?? null, issuer: item.issuer ?? null,
certificateNo: item.certificateNo ? Extension.ToThaiNumber(item.certificateNo) : null, certificateNo: item.certificateNo ? Extension.ToThaiNumber(item.certificateNo) : null,
@ -1091,7 +1079,7 @@ export class ProfileController extends Controller {
}); });
const trainings = const trainings =
training_raw.length > 0 training_raw.length > 0
? training_raw.slice(-2).map((item) => ({ ? training_raw.map((item) => ({
institute: item.department ?? "", institute: item.department ?? "",
start: start:
item.startDate == null item.startDate == null
@ -1128,7 +1116,7 @@ export class ProfileController extends Controller {
}); });
const disciplines = const disciplines =
discipline_raw.length > 0 discipline_raw.length > 0
? discipline_raw.slice(-2).map((item) => ({ ? discipline_raw.map((item) => ({
disciplineYear: item.refCommandDate disciplineYear: item.refCommandDate
? Extension.ToThaiNumber(new Date(item.refCommandDate).getFullYear().toString()) ? Extension.ToThaiNumber(new Date(item.refCommandDate).getFullYear().toString())
: null, : null,
@ -1143,47 +1131,38 @@ export class ProfileController extends Controller {
}, },
]; ];
const education_raw = await this.profileEducationRepo.find({ const education_raw = await this.profileEducationRepo
select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"], .createQueryBuilder("education")
where: { profileId: id }, .where("education.profileId = :profileId", { profileId: id })
// order: { lastUpdatedAt: "DESC" }, .orderBy("CASE WHEN education.isEducation = true THEN 1 ELSE 2 END", "ASC")
order: { level: "ASC" }, .addOrderBy("education.level", "ASC")
}); .getMany();
const educations = const educations =
education_raw.length > 0 education_raw.length > 0
? education_raw.slice(-2).map((item) => ({ ? education_raw.map((item) => ({
institute: item.institute, institute: item.institute,
start: date:
item.startDate == null item.isDate
? "" ? item.startDate && item.endDate
: Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString()), ? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}`
end: : ""
item.endDate == null : item.startDate && item.endDate
? "" ? `${Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString())} - ${Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString())}`
: Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString()), : "",
date:
item.startDate && item.endDate
? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}`
: "",
level: item.educationLevel ?? "",
degree: item.degree ? `${item.degree} ${item.field ? item.field : ""}` : "", degree: item.degree ? `${item.degree} ${item.field ? item.field : ""}` : "",
field: item.field ?? "-",
})) }))
: [ : [
{ {
institute: "-", institute: "-",
start: "-",
end: "-",
date: "-", date: "-",
level: "-",
degree: "-", degree: "-",
field: "-",
}, },
]; ];
const salary_raw = await this.salaryRepo.find({ const salary_raw = await this.salaryRepo.find({
select: [ select: [
"commandDateAffect", "commandDateAffect",
"positionName", "positionName",
"posNoAbb",
"posNo", "posNo",
"positionType", "positionType",
"positionLevel", "positionLevel",
@ -1207,7 +1186,9 @@ export class ProfileController extends Controller {
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect)) ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect))
: null, : null,
position: item.positionName != null ? Extension.ToThaiNumber(item.positionName) : null, position: item.positionName != null ? Extension.ToThaiNumber(item.positionName) : null,
posNo: item.posNo != null ? Extension.ToThaiNumber(item.posNo) : null, posNo: item.posNoAbb && item.posNo
? Extension.ToThaiNumber(`${item.posNoAbb}${item.posNo}`)
: null,
salary: salary:
item.amount != null ? Extension.ToThaiNumber(item.amount.toLocaleString()) : null, item.amount != null ? Extension.ToThaiNumber(item.amount.toLocaleString()) : null,
rank: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null, rank: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null,
@ -1447,10 +1428,8 @@ export class ProfileController extends Controller {
commandDateSign: item.commandDateSign commandDateSign: item.commandDateSign
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateSign)) ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateSign))
: "", : "",
posNo: item.posNoAbb posNo: item.posNoAbb && item.posNo
? Extension.ToThaiNumber(item.posNoAbb) ? Extension.ToThaiNumber(`${item.posNoAbb}${item.posNo}`)
: "" + item.posNo
? Extension.ToThaiNumber(item.posNo)
: "", : "",
position: item.positionName, position: item.positionName,
posType: item.positionType, posType: item.positionType,
@ -1676,6 +1655,9 @@ export class ProfileController extends Controller {
appointDate: profiles?.dateAppoint appointDate: profiles?.dateAppoint
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateAppoint)) ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateAppoint))
: "", : "",
positionDate: positionList.length > 0
? positionList[positionList.length-1].commandDateAffect
: "",
citizenId: citizenId:
profiles.citizenId != null ? Extension.ToThaiNumber(profiles.citizenId.toString()) : "", profiles.citizenId != null ? Extension.ToThaiNumber(profiles.citizenId.toString()) : "",
fatherFullName: fatherFullName:

View file

@ -27,6 +27,7 @@ import { TenurePositionOfficer } from "../entities/TenurePositionOfficer";
import { TenureLevelOfficer } from "../entities/TenureLevelOfficer"; import { TenureLevelOfficer } from "../entities/TenureLevelOfficer";
import { TenurePositionEmployee } from "../entities/TenurePositionEmployee"; import { TenurePositionEmployee } from "../entities/TenurePositionEmployee";
import { TenureLevelEmployee } from "../entities/TenureLevelEmployee"; import { TenureLevelEmployee } from "../entities/TenureLevelEmployee";
import { Command } from "../entities/Command";
@Route("api/v1/org/profile/salary") @Route("api/v1/org/profile/salary")
@Tags("ProfileSalary") @Tags("ProfileSalary")
@Security("bearerAuth") @Security("bearerAuth")
@ -39,6 +40,7 @@ export class ProfileSalaryController extends Controller {
private positionEmployeeRepo = AppDataSource.getRepository(TenurePositionEmployee); private positionEmployeeRepo = AppDataSource.getRepository(TenurePositionEmployee);
private levelOfficerRepo = AppDataSource.getRepository(TenureLevelOfficer); private levelOfficerRepo = AppDataSource.getRepository(TenureLevelOfficer);
private levelEmployeeRepo = AppDataSource.getRepository(TenureLevelEmployee); private levelEmployeeRepo = AppDataSource.getRepository(TenureLevelEmployee);
private commandRepository = AppDataSource.getRepository(Command);
@Get("TenurePositionOfficer") @Get("TenurePositionOfficer")
public async cronjobTenurePositionOfficer() { public async cronjobTenurePositionOfficer() {
@ -671,8 +673,24 @@ export class ProfileSalaryController extends Controller {
order: { order: "DESC" }, order: { order: "DESC" },
}); });
const before = null; const before = null;
let _posNumCodeSit: string = ""
const _command = await this.commandRepository.findOne({
where: { id: body.commandId ?? "" }
});
if (_command) {
if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร"
else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร"
else {
let _profileAdmin = await this.profileRepo.findOne({
where: { keycloak: _command?.createdUserId.toString()},
relations: ["current_holders", "current_holders.orgRoot",]
});
_posNumCodeSit = _profileAdmin?.current_holders
.find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? ""
}
}
const data = new ProfileSalary(); const data = new ProfileSalary();
data.posNumCodeSit = _posNumCodeSit;
const meta = { const meta = {
order: dest_item == null ? 1 : dest_item.order + 1, order: dest_item == null ? 1 : dest_item.order + 1,
createdUserId: req.user.sub, createdUserId: req.user.sub,

View file

@ -26,6 +26,7 @@ import { ProfileEmployee } from "../entities/ProfileEmployee";
import { In, LessThan, MoreThan } from "typeorm"; import { In, LessThan, MoreThan } from "typeorm";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils"; import { setLogDataDiff } from "../interfaces/utils";
import { Command } from "../entities/Command";
@Route("api/v1/org/profile-employee/salary") @Route("api/v1/org/profile-employee/salary")
@Tags("ProfileSalary") @Tags("ProfileSalary")
@Security("bearerAuth") @Security("bearerAuth")
@ -33,6 +34,7 @@ export class ProfileSalaryEmployeeController extends Controller {
private profileRepo = AppDataSource.getRepository(ProfileEmployee); private profileRepo = AppDataSource.getRepository(ProfileEmployee);
private salaryRepo = AppDataSource.getRepository(ProfileSalary); private salaryRepo = AppDataSource.getRepository(ProfileSalary);
private salaryHistoryRepo = AppDataSource.getRepository(ProfileSalaryHistory); private salaryHistoryRepo = AppDataSource.getRepository(ProfileSalaryHistory);
private commandRepository = AppDataSource.getRepository(Command);
@Get("user") @Get("user")
public async getSalaryUser(@Request() request: { user: Record<string, any> }) { public async getSalaryUser(@Request() request: { user: Record<string, any> }) {
@ -353,8 +355,24 @@ export class ProfileSalaryEmployeeController extends Controller {
order: { order: "DESC" }, order: { order: "DESC" },
}); });
const before = null; const before = null;
let _posNumCodeSit: string = ""
const _command = await this.commandRepository.findOne({
where: { id: body.commandId ?? "" }
});
if (_command) {
if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร"
else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร"
else {
let _profileAdmin = await this.profileRepo.findOne({
where: { keycloak: _command?.createdUserId.toString()},
relations: ["current_holders", "current_holders.orgRoot",]
});
_posNumCodeSit = _profileAdmin?.current_holders
.find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? ""
}
}
const data = new ProfileSalary(); const data = new ProfileSalary();
data.posNumCodeSit = _posNumCodeSit;
const meta = { const meta = {
order: dest_item == null ? 1 : dest_item.order + 1, order: dest_item == null ? 1 : dest_item.order + 1,
createdUserId: req.user.sub, createdUserId: req.user.sub,

View file

@ -212,6 +212,22 @@ export class ProfileSalaryHistory extends EntityBase {
}) })
commandId: string; commandId: string;
@Column({
nullable: true,
length: 255,
comment: "หน่วยงานที่ออกคำสั่ง",
default: null,
})
posNumCodeSit: string;
@Column({
nullable: true,
length: 255,
comment: "หน่วยงานที่ออกคำสั่ง(ตัวย่อ)",
default: null,
})
posNumCodeSitAbb: string;
@ManyToOne(() => Command, (command) => command.profileSalaryHistorys) @ManyToOne(() => Command, (command) => command.profileSalaryHistorys)
@JoinColumn({ name: "commandId" }) @JoinColumn({ name: "commandId" })
command: Command; command: Command;

File diff suppressed because one or more lines are too long