คำสั่งรักษาการ
This commit is contained in:
parent
4b967b59eb
commit
9276a6095b
3 changed files with 269 additions and 48 deletions
|
|
@ -61,7 +61,7 @@ import {
|
||||||
enableStatus,
|
enableStatus,
|
||||||
getUserByUsername,
|
getUserByUsername,
|
||||||
getRoleMappings,
|
getRoleMappings,
|
||||||
removeUserRoles
|
removeUserRoles,
|
||||||
} from "../keycloak";
|
} from "../keycloak";
|
||||||
import { ProfileEducation, CreateProfileEducation } from "../entities/ProfileEducation";
|
import { ProfileEducation, CreateProfileEducation } from "../entities/ProfileEducation";
|
||||||
import { ProfileEducationHistory } from "../entities/ProfileEducationHistory";
|
import { ProfileEducationHistory } from "../entities/ProfileEducationHistory";
|
||||||
|
|
@ -75,6 +75,10 @@ import querystring from "querystring";
|
||||||
import { SubDistrict } from "../entities/SubDistrict";
|
import { SubDistrict } from "../entities/SubDistrict";
|
||||||
import { District } from "../entities/District";
|
import { District } from "../entities/District";
|
||||||
import { Province } from "../entities/Province";
|
import { Province } from "../entities/Province";
|
||||||
|
import { ProfileAssistance } from "../entities/ProfileAssistance";
|
||||||
|
import { ProfileAssistanceHistory } from "../entities/ProfileAssistanceHistory";
|
||||||
|
import { ProfileActposition } from "../entities/ProfileActposition";
|
||||||
|
import { ProfileActpositionHistory } from "../entities/ProfileActpositionHistory";
|
||||||
|
|
||||||
@Route("api/v1/org/command")
|
@Route("api/v1/org/command")
|
||||||
@Tags("Command")
|
@Tags("Command")
|
||||||
|
|
@ -114,6 +118,10 @@ export class CommandController extends Controller {
|
||||||
private provinceRepo = AppDataSource.getRepository(Province);
|
private provinceRepo = AppDataSource.getRepository(Province);
|
||||||
private districtRepo = AppDataSource.getRepository(District);
|
private districtRepo = AppDataSource.getRepository(District);
|
||||||
private subDistrictRepo = AppDataSource.getRepository(SubDistrict);
|
private subDistrictRepo = AppDataSource.getRepository(SubDistrict);
|
||||||
|
private assistanceRepository = AppDataSource.getRepository(ProfileAssistance);
|
||||||
|
private assistanceHistoryRepository = AppDataSource.getRepository(ProfileAssistanceHistory);
|
||||||
|
private actpositionRepository = AppDataSource.getRepository(ProfileActposition);
|
||||||
|
private actpositionHistoryRepository = AppDataSource.getRepository(ProfileActpositionHistory);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API list รายการคำสั่ง
|
* API list รายการคำสั่ง
|
||||||
|
|
@ -1350,22 +1358,22 @@ export class CommandController extends Controller {
|
||||||
const adminToken = response.data.access_token;
|
const adminToken = response.data.access_token;
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
today.setUTCHours(0, 0, 0, 0);
|
today.setUTCHours(0, 0, 0, 0);
|
||||||
let type: string = "OFFICER"
|
let type: string = "OFFICER";
|
||||||
try {
|
try {
|
||||||
const response_ = await axios.get(
|
const response_ = await axios.get(
|
||||||
process.env.API_URL + `/retirement/update-status/${type}/${today.getFullYear()}`,
|
process.env.API_URL + `/retirement/update-status/${type}/${today.getFullYear()}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${adminToken}`,
|
Authorization: `Bearer ${adminToken}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
api_key: process.env.API_KEY,
|
api_key: process.env.API_KEY,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
if (response && response_.data.result.length > 0) {
|
if (response && response_.data.result.length > 0) {
|
||||||
let profiles: Profile[] = [];
|
let profiles: Profile[] = [];
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
response_.data.result.map(async (x:any) => {
|
response_.data.result.map(async (x: any) => {
|
||||||
const _profile = await this.profileRepository.findOneBy({ id: x.profileId });
|
const _profile = await this.profileRepository.findOneBy({ id: x.profileId });
|
||||||
if (_profile) {
|
if (_profile) {
|
||||||
_profile.isRetirement = true;
|
_profile.isRetirement = true;
|
||||||
|
|
@ -1376,28 +1384,28 @@ export class CommandController extends Controller {
|
||||||
_profile.lastUpdatedAt = new Date();
|
_profile.lastUpdatedAt = new Date();
|
||||||
profiles.push(_profile);
|
profiles.push(_profile);
|
||||||
}
|
}
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
await this.profileRepository.save(profiles);
|
await this.profileRepository.save(profiles);
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
type = "EMPLOYEE"
|
type = "EMPLOYEE";
|
||||||
try {
|
try {
|
||||||
const response_ = await axios.get(
|
const response_ = await axios.get(
|
||||||
process.env.API_URL + `/retirement/update-status/${type}/${today.getFullYear()}`,
|
process.env.API_URL + `/retirement/update-status/${type}/${today.getFullYear()}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${adminToken}`,
|
Authorization: `Bearer ${adminToken}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
api_key: process.env.API_KEY,
|
api_key: process.env.API_KEY,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
if (response && response_.data.result.length > 0) {
|
if (response && response_.data.result.length > 0) {
|
||||||
let profiles: ProfileEmployee[] = [];
|
let profiles: ProfileEmployee[] = [];
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
response_.data.result.map(async (x:any) => {
|
response_.data.result.map(async (x: any) => {
|
||||||
const _profileEmp = await this.profileEmployeeRepository.findOneBy({ id: x.profileId });
|
const _profileEmp = await this.profileEmployeeRepository.findOneBy({ id: x.profileId });
|
||||||
if (_profileEmp) {
|
if (_profileEmp) {
|
||||||
_profileEmp.isRetirement = true;
|
_profileEmp.isRetirement = true;
|
||||||
|
|
@ -1408,7 +1416,7 @@ export class CommandController extends Controller {
|
||||||
_profileEmp.lastUpdatedAt = new Date();
|
_profileEmp.lastUpdatedAt = new Date();
|
||||||
profiles.push(_profileEmp);
|
profiles.push(_profileEmp);
|
||||||
}
|
}
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
await this.profileEmployeeRepository.save(profiles);
|
await this.profileEmployeeRepository.save(profiles);
|
||||||
}
|
}
|
||||||
|
|
@ -3069,6 +3077,9 @@ export class CommandController extends Controller {
|
||||||
mpCee?: string | null;
|
mpCee?: string | null;
|
||||||
refCommandCode?: string | null;
|
refCommandCode?: string | null;
|
||||||
refCommandName?: string | null;
|
refCommandName?: string | null;
|
||||||
|
officerOrg?: string | null;
|
||||||
|
dateStart?: Date | null;
|
||||||
|
dateEnd?: Date | null;
|
||||||
}[];
|
}[];
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
|
|
@ -3135,6 +3146,41 @@ export class CommandController extends Controller {
|
||||||
setLogDataDiff(req, { before, after: data });
|
setLogDataDiff(req, { before, after: data });
|
||||||
history.profileSalaryId = data.id;
|
history.profileSalaryId = data.id;
|
||||||
await this.salaryHistoryRepo.save(history, { data: req });
|
await this.salaryHistoryRepo.save(history, { data: req });
|
||||||
|
|
||||||
|
if (item.commandId) {
|
||||||
|
const command = await this.commandRepository.findOne({
|
||||||
|
where: { id: item.commandId },
|
||||||
|
relations: ["commandType"],
|
||||||
|
});
|
||||||
|
if (command != null && command.commandType.code == "C-PM-15") {
|
||||||
|
// ประวัติคำสั่งให้ช่วยราชการ
|
||||||
|
const dataAssis = new ProfileAssistance();
|
||||||
|
|
||||||
|
const metaAssis = {
|
||||||
|
profileId: item.profileId,
|
||||||
|
agency: item.officerOrg,
|
||||||
|
dateStart: item.dateStart,
|
||||||
|
dateEnd: item.dateEnd,
|
||||||
|
commandNo: item.refCommandNo,
|
||||||
|
refCommandDate: new Date(),
|
||||||
|
commandId: item.commandId,
|
||||||
|
createdUserId: req.user.sub,
|
||||||
|
createdFullName: req.user.name,
|
||||||
|
lastUpdateUserId: req.user.sub,
|
||||||
|
lastUpdateFullName: req.user.name,
|
||||||
|
createdAt: new Date(),
|
||||||
|
lastUpdatedAt: new Date(),
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.assign(dataAssis, metaAssis);
|
||||||
|
const historyAssis = new ProfileAssistanceHistory();
|
||||||
|
Object.assign(historyAssis, { ...dataAssis, id: undefined });
|
||||||
|
|
||||||
|
await this.assistanceRepository.save(dataAssis);
|
||||||
|
historyAssis.profileAssistanceId = dataAssis.id;
|
||||||
|
await this.assistanceHistoryRepository.save(historyAssis);
|
||||||
|
}
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -3159,6 +3205,7 @@ export class CommandController extends Controller {
|
||||||
positionLevel: string | null;
|
positionLevel: string | null;
|
||||||
refCommandNo: string | null;
|
refCommandNo: string | null;
|
||||||
templateDoc: string | null;
|
templateDoc: string | null;
|
||||||
|
commandId?: string | null;
|
||||||
orgRoot?: string | null;
|
orgRoot?: string | null;
|
||||||
orgChild1?: string | null;
|
orgChild1?: string | null;
|
||||||
orgChild2?: string | null;
|
orgChild2?: string | null;
|
||||||
|
|
@ -3167,6 +3214,9 @@ export class CommandController extends Controller {
|
||||||
mpCee?: string | null;
|
mpCee?: string | null;
|
||||||
refCommandCode?: string | null;
|
refCommandCode?: string | null;
|
||||||
refCommandName?: string | null;
|
refCommandName?: string | null;
|
||||||
|
officerOrg?: string | null;
|
||||||
|
dateStart?: Date | null;
|
||||||
|
dateEnd?: Date | null;
|
||||||
}[];
|
}[];
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
|
|
@ -3208,6 +3258,40 @@ export class CommandController extends Controller {
|
||||||
setLogDataDiff(req, { before, after: data });
|
setLogDataDiff(req, { before, after: data });
|
||||||
history.profileSalaryId = data.id;
|
history.profileSalaryId = data.id;
|
||||||
await this.salaryHistoryRepo.save(history, { data: req });
|
await this.salaryHistoryRepo.save(history, { data: req });
|
||||||
|
if (item.commandId) {
|
||||||
|
const command = await this.commandRepository.findOne({
|
||||||
|
where: { id: item.commandId },
|
||||||
|
relations: ["commandType"],
|
||||||
|
});
|
||||||
|
if (command != null && command.commandType.code == "C-PM-15") {
|
||||||
|
// ประวัติคำสั่งให้ช่วยราชการ
|
||||||
|
const dataAssis = new ProfileAssistance();
|
||||||
|
|
||||||
|
const metaAssis = {
|
||||||
|
profileId: item.profileId,
|
||||||
|
agency: item.officerOrg,
|
||||||
|
dateStart: item.dateStart,
|
||||||
|
dateEnd: item.dateEnd,
|
||||||
|
commandNo: item.refCommandNo,
|
||||||
|
refCommandDate: new Date(),
|
||||||
|
commandId: item.commandId,
|
||||||
|
createdUserId: req.user.sub,
|
||||||
|
createdFullName: req.user.name,
|
||||||
|
lastUpdateUserId: req.user.sub,
|
||||||
|
lastUpdateFullName: req.user.name,
|
||||||
|
createdAt: new Date(),
|
||||||
|
lastUpdatedAt: new Date(),
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.assign(dataAssis, metaAssis);
|
||||||
|
const historyAssis = new ProfileAssistanceHistory();
|
||||||
|
Object.assign(historyAssis, { ...dataAssis, id: undefined });
|
||||||
|
|
||||||
|
await this.assistanceRepository.save(dataAssis);
|
||||||
|
historyAssis.profileAssistanceId = dataAssis.id;
|
||||||
|
await this.assistanceHistoryRepository.save(historyAssis);
|
||||||
|
}
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -4216,8 +4300,7 @@ export class CommandController extends Controller {
|
||||||
where: { name: Like("USER") },
|
where: { name: Like("USER") },
|
||||||
});
|
});
|
||||||
const list = await getRoles();
|
const list = await getRoles();
|
||||||
if (!Array.isArray(list))
|
if (!Array.isArray(list)) throw new Error("Failed. Cannot get role(s) data from the server.");
|
||||||
throw new Error("Failed. Cannot get role(s) data from the server.");
|
|
||||||
const _null: any = null;
|
const _null: any = null;
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
body.data.map(async (item) => {
|
body.data.map(async (item) => {
|
||||||
|
|
@ -4246,7 +4329,7 @@ export class CommandController extends Controller {
|
||||||
) {
|
) {
|
||||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
|
||||||
}
|
}
|
||||||
|
|
||||||
let registrationProvinceId = await this.provinceRepo.findOneBy({
|
let registrationProvinceId = await this.provinceRepo.findOneBy({
|
||||||
id: item.bodyProfile.registrationProvinceId ?? "",
|
id: item.bodyProfile.registrationProvinceId ?? "",
|
||||||
});
|
});
|
||||||
|
|
@ -4265,22 +4348,28 @@ export class CommandController extends Controller {
|
||||||
let currentSubDistrictId = await this.subDistrictRepo.findOneBy({
|
let currentSubDistrictId = await this.subDistrictRepo.findOneBy({
|
||||||
id: item.bodyProfile.currentSubDistrictId ?? "",
|
id: item.bodyProfile.currentSubDistrictId ?? "",
|
||||||
});
|
});
|
||||||
|
|
||||||
let _dateRetire = item.bodyProfile.birthDate == null
|
let _dateRetire =
|
||||||
? _null
|
item.bodyProfile.birthDate == null
|
||||||
: calculateRetireDate(item.bodyProfile.birthDate);
|
? _null
|
||||||
let _dateRetireLaw = item.bodyProfile.birthDate == null
|
: calculateRetireDate(item.bodyProfile.birthDate);
|
||||||
? _null
|
let _dateRetireLaw =
|
||||||
: calculateRetireLaw(item.bodyProfile.birthDate);
|
item.bodyProfile.birthDate == null
|
||||||
|
? _null
|
||||||
let userKeycloakId:any
|
: calculateRetireLaw(item.bodyProfile.birthDate);
|
||||||
let result:any
|
|
||||||
|
let userKeycloakId: any;
|
||||||
|
let result: any;
|
||||||
const checkUser = await getUserByUsername(item.bodyProfile.citizenId);
|
const checkUser = await getUserByUsername(item.bodyProfile.citizenId);
|
||||||
if (checkUser.length == 0) {
|
if (checkUser.length == 0) {
|
||||||
userKeycloakId = await createUser(item.bodyProfile.citizenId, item.bodyProfile.citizenId, {
|
userKeycloakId = await createUser(
|
||||||
firstName: item.bodyProfile.firstName,
|
item.bodyProfile.citizenId,
|
||||||
lastName: item.bodyProfile.lastName,
|
item.bodyProfile.citizenId,
|
||||||
});
|
{
|
||||||
|
firstName: item.bodyProfile.firstName,
|
||||||
|
lastName: item.bodyProfile.lastName,
|
||||||
|
},
|
||||||
|
);
|
||||||
result = await addUserRoles(
|
result = await addUserRoles(
|
||||||
userKeycloakId,
|
userKeycloakId,
|
||||||
list
|
list
|
||||||
|
|
@ -4294,14 +4383,11 @@ export class CommandController extends Controller {
|
||||||
userKeycloakId = checkUser[0].id;
|
userKeycloakId = checkUser[0].id;
|
||||||
const rolesData = await getRoleMappings(userKeycloakId);
|
const rolesData = await getRoleMappings(userKeycloakId);
|
||||||
if (rolesData) {
|
if (rolesData) {
|
||||||
const _delRole = rolesData.map((x:any) => ({
|
const _delRole = rolesData.map((x: any) => ({
|
||||||
id : x.id,
|
id: x.id,
|
||||||
name: x.name
|
name: x.name,
|
||||||
}));
|
}));
|
||||||
await removeUserRoles(
|
await removeUserRoles(userKeycloakId, _delRole);
|
||||||
userKeycloakId,
|
|
||||||
_delRole
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
result = await addUserRoles(
|
result = await addUserRoles(
|
||||||
userKeycloakId,
|
userKeycloakId,
|
||||||
|
|
@ -4315,19 +4401,26 @@ export class CommandController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
let profile: any = await this.profileRepository.findOne({
|
let profile: any = await this.profileRepository.findOne({
|
||||||
where: { citizenId: item.bodyProfile.citizenId/*, isActive: true */},
|
where: { citizenId: item.bodyProfile.citizenId /*, isActive: true */ },
|
||||||
relations: ["roleKeycloaks"],
|
relations: ["roleKeycloaks"],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!profile) {
|
if (!profile) {
|
||||||
profile = Object.assign({ ...item.bodyProfile, ...meta });
|
profile = Object.assign({ ...item.bodyProfile, ...meta });
|
||||||
profile.dateRetire = _dateRetire;
|
profile.dateRetire = _dateRetire;
|
||||||
profile.dateRetireLaw = _dateRetireLaw
|
profile.dateRetireLaw = _dateRetireLaw;
|
||||||
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
|
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
|
||||||
profile.keycloak = userKeycloakId && typeof userKeycloakId === "string" ? userKeycloakId : ""
|
profile.keycloak =
|
||||||
profile.registrationProvinceId = registrationProvinceId ? registrationProvinceId.id : _null;
|
userKeycloakId && typeof userKeycloakId === "string" ? userKeycloakId : "";
|
||||||
profile.registrationDistrictId = registrationDistrictId ? registrationDistrictId.id : _null;
|
profile.registrationProvinceId = registrationProvinceId
|
||||||
profile.registrationSubDistrictId = registrationSubDistrictId ? registrationSubDistrictId.id : _null;
|
? registrationProvinceId.id
|
||||||
|
: _null;
|
||||||
|
profile.registrationDistrictId = registrationDistrictId
|
||||||
|
? registrationDistrictId.id
|
||||||
|
: _null;
|
||||||
|
profile.registrationSubDistrictId = registrationSubDistrictId
|
||||||
|
? registrationSubDistrictId.id
|
||||||
|
: _null;
|
||||||
profile.currentProvinceId = currentProvinceId ? currentProvinceId.id : _null;
|
profile.currentProvinceId = currentProvinceId ? currentProvinceId.id : _null;
|
||||||
profile.currentDistrictId = currentDistrictId ? currentDistrictId.id : _null;
|
profile.currentDistrictId = currentDistrictId ? currentDistrictId.id : _null;
|
||||||
profile.currentSubDistrictId = currentSubDistrictId ? currentSubDistrictId.id : _null;
|
profile.currentSubDistrictId = currentSubDistrictId ? currentSubDistrictId.id : _null;
|
||||||
|
|
@ -4339,20 +4432,27 @@ export class CommandController extends Controller {
|
||||||
await this.profileRepository.save(profile);
|
await this.profileRepository.save(profile);
|
||||||
setLogDataDiff(req, { before, after: profile });
|
setLogDataDiff(req, { before, after: profile });
|
||||||
}
|
}
|
||||||
//ขรก.ในระบบ หรือ ขรก.ในระบบที่สถานะพ้นจากราชการ
|
//ขรก.ในระบบ หรือ ขรก.ในระบบที่สถานะพ้นจากราชการ
|
||||||
else {
|
else {
|
||||||
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
|
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
|
||||||
profile.keycloak = userKeycloakId && typeof userKeycloakId === "string" ? userKeycloakId : "";
|
profile.keycloak =
|
||||||
|
userKeycloakId && typeof userKeycloakId === "string" ? userKeycloakId : "";
|
||||||
profile.isProbation = item.bodyProfile.isProbation;
|
profile.isProbation = item.bodyProfile.isProbation;
|
||||||
profile.isLeave = item.bodyProfile.isLeave;
|
profile.isLeave = item.bodyProfile.isLeave;
|
||||||
profile.isRetirement = false;
|
profile.isRetirement = false;
|
||||||
profile.isActive = true;
|
profile.isActive = true;
|
||||||
profile.dateLeave = _null;
|
profile.dateLeave = _null;
|
||||||
profile.dateRetire = _dateRetire;
|
profile.dateRetire = _dateRetire;
|
||||||
profile.dateRetireLaw = _dateRetireLaw
|
profile.dateRetireLaw = _dateRetireLaw;
|
||||||
profile.registrationProvinceId = registrationProvinceId ? registrationProvinceId.id : _null;
|
profile.registrationProvinceId = registrationProvinceId
|
||||||
profile.registrationDistrictId = registrationDistrictId ? registrationDistrictId.id : _null;
|
? registrationProvinceId.id
|
||||||
profile.registrationSubDistrictId = registrationSubDistrictId ? registrationSubDistrictId.id : _null;
|
: _null;
|
||||||
|
profile.registrationDistrictId = registrationDistrictId
|
||||||
|
? registrationDistrictId.id
|
||||||
|
: _null;
|
||||||
|
profile.registrationSubDistrictId = registrationSubDistrictId
|
||||||
|
? registrationSubDistrictId.id
|
||||||
|
: _null;
|
||||||
profile.currentProvinceId = currentProvinceId ? currentProvinceId.id : _null;
|
profile.currentProvinceId = currentProvinceId ? currentProvinceId.id : _null;
|
||||||
profile.currentDistrictId = currentDistrictId ? currentDistrictId.id : _null;
|
profile.currentDistrictId = currentDistrictId ? currentDistrictId.id : _null;
|
||||||
profile.currentSubDistrictId = currentSubDistrictId ? currentSubDistrictId.id : _null;
|
profile.currentSubDistrictId = currentSubDistrictId ? currentSubDistrictId.id : _null;
|
||||||
|
|
@ -4372,7 +4472,7 @@ export class CommandController extends Controller {
|
||||||
await this.profileRepository.save(profile);
|
await this.profileRepository.save(profile);
|
||||||
setLogDataDiff(req, { before, after: profile });
|
setLogDataDiff(req, { before, after: profile });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (profile && profile.id) {
|
if (profile && profile.id) {
|
||||||
//Educations
|
//Educations
|
||||||
if (item.bodyEducations && item.bodyEducations.length > 0) {
|
if (item.bodyEducations && item.bodyEducations.length > 0) {
|
||||||
|
|
@ -4805,12 +4905,79 @@ export class CommandController extends Controller {
|
||||||
) {
|
) {
|
||||||
const posMasters = await this.posMasterActRepository.find({
|
const posMasters = await this.posMasterActRepository.find({
|
||||||
where: { id: In(body.refIds.map((x) => x.refId)) },
|
where: { id: In(body.refIds.map((x) => x.refId)) },
|
||||||
|
relations: [
|
||||||
|
"posMasterChild",
|
||||||
|
"posMaster",
|
||||||
|
"posMaster.current_holder",
|
||||||
|
"posMaster.orgRoot",
|
||||||
|
"posMaster.orgChild1",
|
||||||
|
"posMaster.orgChild2",
|
||||||
|
"posMaster.orgChild3",
|
||||||
|
"posMaster.orgChild4",
|
||||||
|
],
|
||||||
});
|
});
|
||||||
const data = posMasters.map((_data) => ({
|
const data = posMasters.map((_data) => ({
|
||||||
..._data,
|
..._data,
|
||||||
statusReport: "PENDING",
|
statusReport: "PENDING",
|
||||||
}));
|
}));
|
||||||
await this.posMasterActRepository.save(data);
|
await this.posMasterActRepository.save(data);
|
||||||
|
|
||||||
|
await Promise.all(
|
||||||
|
posMasters.map(async (item) => {
|
||||||
|
if (item.posMasterChild != null && item.posMasterChild.current_holderId != null) {
|
||||||
|
// ประวัติคำสั่งให้รักษาการแทน
|
||||||
|
const dataAct = new ProfileActposition();
|
||||||
|
const _actposition = await this.actpositionRepository.find({
|
||||||
|
where: { profileId: item.posMasterChild.current_holderId },
|
||||||
|
});
|
||||||
|
const data = _actposition.map((_data) => ({
|
||||||
|
..._data,
|
||||||
|
status: false,
|
||||||
|
dateEnd: _data.status == true ? new Date() : _data.dateEnd,
|
||||||
|
}));
|
||||||
|
await this.posMasterActRepository.save(data);
|
||||||
|
item.posMasterChild.current_holderId;
|
||||||
|
|
||||||
|
const shortName =
|
||||||
|
item.posMaster != null && item.posMaster.orgChild4 != null
|
||||||
|
? `${item.posMaster.orgChild4.orgChild4ShortName}${item.posMaster.posMasterNo}`
|
||||||
|
: item.posMaster != null && item.posMaster?.orgChild3 != null
|
||||||
|
? `${item.posMaster.orgChild3.orgChild3ShortName}${item.posMaster.posMasterNo}`
|
||||||
|
: item.posMaster != null && item.posMaster?.orgChild2 != null
|
||||||
|
? `${item.posMaster.orgChild2.orgChild2ShortName}${item.posMaster.posMasterNo}`
|
||||||
|
: item.posMaster != null && item.posMaster?.orgChild1 != null
|
||||||
|
? `${item.posMaster.orgChild1.orgChild1ShortName}${item.posMaster.posMasterNo}`
|
||||||
|
: item.posMaster != null && item.posMaster?.orgRoot != null
|
||||||
|
? `${item.posMaster.orgRoot.orgRootShortName}${item.posMaster.posMasterNo}`
|
||||||
|
: null;
|
||||||
|
const metaAct = {
|
||||||
|
profileId: item.posMasterChild.current_holderId,
|
||||||
|
dateStart: new Date(),
|
||||||
|
dateEnd: null,
|
||||||
|
posNo: shortName,
|
||||||
|
position: item.posMaster.current_holder.position,
|
||||||
|
status: true,
|
||||||
|
commandNo: `${body.refIds[0].commandNo}/${Extension.ToThaiYear(body.refIds[0].commandYear)}`,
|
||||||
|
refCommandDate: new Date(),
|
||||||
|
commandId: body.refIds[0].commandId,
|
||||||
|
createdUserId: req.user.sub,
|
||||||
|
createdFullName: req.user.name,
|
||||||
|
lastUpdateUserId: req.user.sub,
|
||||||
|
lastUpdateFullName: req.user.name,
|
||||||
|
createdAt: new Date(),
|
||||||
|
lastUpdatedAt: new Date(),
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.assign(dataAct, metaAct);
|
||||||
|
const historyAct = new ProfileActpositionHistory();
|
||||||
|
Object.assign(historyAct, { ...dataAct, id: undefined });
|
||||||
|
|
||||||
|
await this.actpositionRepository.save(dataAct);
|
||||||
|
historyAct.profileActpositionId = dataAct.id;
|
||||||
|
await this.actpositionHistoryRepository.save(historyAct);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { EntityBase } from "./base/Base";
|
||||||
import { Profile } from "./Profile";
|
import { Profile } from "./Profile";
|
||||||
import { ProfileActpositionHistory } from "./ProfileActpositionHistory";
|
import { ProfileActpositionHistory } from "./ProfileActpositionHistory";
|
||||||
import { ProfileEmployee } from "./ProfileEmployee";
|
import { ProfileEmployee } from "./ProfileEmployee";
|
||||||
|
import { Command } from "./Command";
|
||||||
|
|
||||||
@Entity("profileActposition")
|
@Entity("profileActposition")
|
||||||
export class ProfileActposition extends EntityBase {
|
export class ProfileActposition extends EntityBase {
|
||||||
|
|
@ -50,6 +51,33 @@ export class ProfileActposition extends EntityBase {
|
||||||
})
|
})
|
||||||
status: boolean;
|
status: boolean;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
comment: "เลขที่คำสั่ง",
|
||||||
|
type: "text",
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
refCommandNo: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
comment: "วันที่ออกคำสั่ง",
|
||||||
|
type: "datetime",
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
refCommandDate: Date;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
length: 40,
|
||||||
|
comment: "คีย์นอก(FK)ของตาราง command",
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
commandId: string;
|
||||||
|
|
||||||
|
@ManyToOne(() => Command, (command) => command.profileSalarys)
|
||||||
|
@JoinColumn({ name: "commandId" })
|
||||||
|
command: Command;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
length: 40,
|
length: 40,
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { EntityBase } from "./base/Base";
|
||||||
import { Profile } from "./Profile";
|
import { Profile } from "./Profile";
|
||||||
import { ProfileAssistanceHistory } from "./ProfileAssistanceHistory";
|
import { ProfileAssistanceHistory } from "./ProfileAssistanceHistory";
|
||||||
import { ProfileEmployee } from "./ProfileEmployee";
|
import { ProfileEmployee } from "./ProfileEmployee";
|
||||||
|
import { Command } from "./Command";
|
||||||
|
|
||||||
@Entity("profileAssistance")
|
@Entity("profileAssistance")
|
||||||
export class ProfileAssistance extends EntityBase {
|
export class ProfileAssistance extends EntityBase {
|
||||||
|
|
@ -57,6 +58,25 @@ export class ProfileAssistance extends EntityBase {
|
||||||
})
|
})
|
||||||
isUpload: boolean;
|
isUpload: boolean;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
comment: "วันที่ออกคำสั่ง",
|
||||||
|
type: "datetime",
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
refCommandDate: Date;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
length: 40,
|
||||||
|
comment: "คีย์นอก(FK)ของตาราง command",
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
commandId: string;
|
||||||
|
|
||||||
|
@ManyToOne(() => Command, (command) => command.profileSalarys)
|
||||||
|
@JoinColumn({ name: "commandId" })
|
||||||
|
command: Command;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
length: 40,
|
length: 40,
|
||||||
|
|
@ -87,6 +107,8 @@ export class CreateProfileAssistance {
|
||||||
dateEnd: Date | null;
|
dateEnd: Date | null;
|
||||||
commandNo: string | null;
|
commandNo: string | null;
|
||||||
document: string | null;
|
document: string | null;
|
||||||
|
refCommandDate?: string | null;
|
||||||
|
commandId?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreateProfileAssistanceEmployee {
|
export class CreateProfileAssistanceEmployee {
|
||||||
|
|
@ -96,6 +118,8 @@ export class CreateProfileAssistanceEmployee {
|
||||||
dateEnd: Date | null;
|
dateEnd: Date | null;
|
||||||
commandNo: string | null;
|
commandNo: string | null;
|
||||||
document: string | null;
|
document: string | null;
|
||||||
|
refCommandDate?: string | null;
|
||||||
|
commandId?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type UpdateProfileAssistance = {
|
export type UpdateProfileAssistance = {
|
||||||
|
|
@ -105,4 +129,6 @@ export type UpdateProfileAssistance = {
|
||||||
commandNo?: string | null;
|
commandNo?: string | null;
|
||||||
document?: string | null;
|
document?: string | null;
|
||||||
isUpload?: boolean | null;
|
isUpload?: boolean | null;
|
||||||
|
refCommandDate?: string | null;
|
||||||
|
commandId?: string | null;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue