no message

This commit is contained in:
kittapath 2024-11-14 18:03:56 +07:00
parent ff49b53713
commit c0bfd46fc3
4 changed files with 365 additions and 122 deletions

View file

@ -1326,7 +1326,7 @@ export class CommandController extends Controller {
RemarkHorizontal: x.remarkHorizontal,
RemarkVertical: x.remarkVertical,
CommandYear: command.commandYear,
CommandExcecuteDate: command.commandExcecuteDate
CommandExcecuteDate: command.commandExcecuteDate,
})),
})
.then(async (res) => {
@ -1658,8 +1658,8 @@ export class CommandController extends Controller {
},
select: ["orgRootId"],
});
let _posMaster : any
if(["C-PM-38", "C-PM-40"].includes(commandCode)) {
let _posMaster: any;
if (["C-PM-38", "C-PM-40"].includes(commandCode)) {
_posMaster = await this.posMasterRepository.find({
where: {
orgRootId: In(posMaster.map((x) => x.orgRootId)),
@ -1673,8 +1673,7 @@ export class CommandController extends Controller {
},
relations: ["current_holder", "orgRoot"],
});
}
else {
} else {
_posMaster = await this.posMasterRepository.find({
where: {
orgRootId: In(posMaster.map((x) => x.orgRootId)),
@ -1686,7 +1685,7 @@ export class CommandController extends Controller {
});
}
await Promise.all(
_posMaster.map(async (item:any) => {
_posMaster.map(async (item: any) => {
const _commandSend = await this.commandSendRepository.findOne({
where: {
commandId: command.id,
@ -1710,14 +1709,16 @@ export class CommandController extends Controller {
commandSend.lastUpdateFullName = request.user.name;
commandSend.lastUpdatedAt = new Date();
await this.commandSendRepository.save(commandSend);
}),
}),
);
const _posMasterNext = await this.posMasterRepository.find({
where: {
orgRootId: In(requestBody.persons
.filter((x) => x.rootId != undefined && x.rootId != null && x.rootId != "")
.map((x) => x.rootId)),
orgRootId: In(
requestBody.persons
.filter((x) => x.rootId != undefined && x.rootId != null && x.rootId != "")
.map((x) => x.rootId),
),
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
isDirector: true,
current_holderId: Not(IsNull()),
@ -1952,7 +1953,7 @@ export class CommandController extends Controller {
},
});
if (posMasterOld != null) posMasterOld.current_holderId = null;
if (posMasterOld != null) posMasterOld.next_holderId = null;
// if (posMasterOld != null) posMasterOld.next_holderId = null;
const positionOld = await this.employeePositionRepository.findOne({
where: {
@ -1980,7 +1981,7 @@ export class CommandController extends Controller {
}
posMaster.current_holderId = item.profileId;
posMaster.next_holderId = item.profileId;
posMaster.next_holderId = null;
if (posMasterOld != null) await this.employeePosMasterRepository.save(posMasterOld);
await this.employeePosMasterRepository.save(posMaster);
@ -2042,8 +2043,8 @@ export class CommandController extends Controller {
body.data.map(async (item) => {
const profile = await this.profileRepository.findOne({
where: { id: item.profileId },
relations: ["roleKeycloaks"]
})
relations: ["roleKeycloaks"],
});
if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
}
@ -2098,11 +2099,10 @@ export class CommandController extends Controller {
}
const returnWork = await checkReturnCommandType(String(item.commandId));
if (returnWork && item.isGovernment) {
if (profile.keycloak != null ) {
if (profile.keycloak != null) {
const enableActive = await enableStatus(profile.keycloak, true);
if (!enableActive) throw new Error("Failed. Cannot change enable status.");
}
else {
} else {
const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
firstName: profile.firstName,
lastName: profile.lastName,
@ -2163,8 +2163,8 @@ export class CommandController extends Controller {
await Promise.all(
body.data.map(async (item) => {
const profile = await this.profileEmployeeRepository.findOne({
where: {id: item.profileId},
relations: ["roleKeycloaks"]
where: { id: item.profileId },
relations: ["roleKeycloaks"],
});
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
@ -2258,10 +2258,10 @@ export class CommandController extends Controller {
) {
await Promise.all(
body.data.map(async (item) => {
const profile = await this.profileRepository.findOne({
const profile = await this.profileRepository.findOne({
where: { id: item.profileId },
relations: ["roleKeycloaks"]
});
relations: ["roleKeycloaks"],
});
if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
}
@ -2282,7 +2282,7 @@ export class CommandController extends Controller {
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
if(item.isLeave != undefined && item.isLeave == true) {
if (item.isLeave != undefined && item.isLeave == true) {
await removeProfileInOrganize(profile.id, "OFFICER");
}
const clearProfile = await checkCommandType(String(item.commandId));
@ -2405,7 +2405,7 @@ export class CommandController extends Controller {
await Promise.all(
body.data.map(async (item) => {
const profile = await this.profileRepository.findOne({
relations: ["profileSalary","posLevel","posType","current_holders", "roleKeycloaks"],
relations: ["profileSalary", "posLevel", "posType", "current_holders", "roleKeycloaks"],
where: { id: item.profileId },
order: {
profileSalary: {
@ -2417,17 +2417,17 @@ export class CommandController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
}
const orgRevision = await this.orgRevisionRepo.findOne({
where:{
where: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
})
orgRevisionIsDraft: false,
},
});
const shortName =
!profile.current_holders || profile.current_holders.length == 0
!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 != 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)
@ -2437,7 +2437,8 @@ export class CommandController extends Controller {
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) !=
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}`
@ -2447,7 +2448,10 @@ export class CommandController extends Controller {
?.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;
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 = {
@ -2459,7 +2463,7 @@ export class CommandController extends Controller {
position: profile.position,
positionType: profile.posType.posTypeName,
positionLevel: profile.posLevel.posLevelName,
posNo: shortName?shortName:"-",
posNo: shortName ? shortName : "-",
positionLine: position?.positionField ?? "-",
positionPathSide: position?.positionArea ?? "-",
positionExecutive: position?.posExecutive?.posExecutiveName ?? "-",
@ -2528,8 +2532,7 @@ export class CommandController extends Controller {
const exceptClear = await checkExceptCommandType(String(item.commandId));
if (item.isLeave == true && !exceptClear) {
await removeProfileInOrganize(_profile.id, "OFFICER");
}
else if (item.isLeave == true && exceptClear && _profile.keycloak != null) {
} 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.");
_profile.isActive = false;
@ -2596,18 +2599,18 @@ export class CommandController extends Controller {
}
const orgRevision = await this.orgRevisionRepo.findOne({
where:{
where: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
})
orgRevisionIsDraft: false,
},
});
const shortName =
!profile.current_holders || profile.current_holders.length == 0
!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 != 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)
@ -2617,7 +2620,8 @@ export class CommandController extends Controller {
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) !=
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}`
@ -2627,7 +2631,10 @@ export class CommandController extends Controller {
?.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;
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 = {
@ -2639,7 +2646,7 @@ export class CommandController extends Controller {
position: profile.position,
positionType: profile.posType.posTypeName,
positionLevel: profile.posLevel.posLevelName,
posNo: shortName?shortName:"-",
posNo: shortName ? shortName : "-",
positionLine: position?.positionField ?? "-",
positionPathSide: position?.positionArea ?? "-",
positionExecutive: position?.posExecutive?.posExecutiveName ?? "-",
@ -2669,11 +2676,13 @@ export class CommandController extends Controller {
}),
);
const checkCommandType = await this.commandRepository.findOne({
where: { id: (body.data.length > 0 ? body.data[0].commandId?.toString() : "") },
relations: ["commandType"]
where: { id: body.data.length > 0 ? body.data[0].commandId?.toString() : "" },
relations: ["commandType"],
});
if(checkCommandType?.commandType.code == "C-PM-11") {
const profile = await this.profileRepository.find({ where: { id: In(body.data.map(x => x.profileId)) } });
if (checkCommandType?.commandType.code == "C-PM-11") {
const profile = await this.profileRepository.find({
where: { id: In(body.data.map((x) => x.profileId)) },
});
const data = profile.map((x) => ({
...x,
isProbation: false,
@ -2704,7 +2713,14 @@ export class CommandController extends Controller {
await Promise.all(
body.data.map(async (item) => {
const profile = await this.profileRepository.findOne({
relations: ["profileSalary","posType","posLevel",'current_holders','current_holders.positions','current_holders.positions.posExecutive'],
relations: [
"profileSalary",
"posType",
"posLevel",
"current_holders",
"current_holders.positions",
"current_holders.positions.posExecutive",
],
where: { id: item.profileId },
order: {
profileSalary: {
@ -2717,7 +2733,7 @@ export class CommandController extends Controller {
}
const _profile = await this.profileRepository.findOne({
where: { id: item.profileId },
relations: ["roleKeycloaks"]
relations: ["roleKeycloaks"],
});
if (!_profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
@ -2732,17 +2748,17 @@ export class CommandController extends Controller {
_profile.lastUpdatedAt = new Date();
const orgRevision = await this.orgRevisionRepo.findOne({
where:{
where: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
})
orgRevisionIsDraft: false,
},
});
const shortName =
!profile.current_holders || profile.current_holders.length == 0
!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 != 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)
@ -2752,7 +2768,8 @@ export class CommandController extends Controller {
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) !=
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}`
@ -2762,7 +2779,10 @@ export class CommandController extends Controller {
?.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;
let position =
profile.current_holders
.filter((x) => x.orgRevisionId == orgRevision?.id)[0]
?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null;
const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), {
profileId: item.profileId,
date: item.date,
@ -2798,23 +2818,23 @@ export class CommandController extends Controller {
const clearProfile = await checkCommandType(String(item.commandId));
const _null: any = null;
if (clearProfile) {
if (_profile.keycloak != null) {
const delUserKeycloak = await deleteUser(_profile.keycloak);
if (delUserKeycloak) _profile.keycloak = _null;
_profile.roleKeycloaks = [];
}
_profile.position = _null;
_profile.posTypeId = _null;
_profile.posLevelId = _null;
}
await Promise.all([
this.profileRepository.save(_profile),
this.salaryRepo.save(profileSalary),
]);
const history = new ProfileSalaryHistory();
Object.assign(history, { ...profileSalary, id: undefined });
history.profileSalaryId = profileSalary.id;
await this.salaryHistoryRepo.save(history);
if (_profile.keycloak != null) {
const delUserKeycloak = await deleteUser(_profile.keycloak);
if (delUserKeycloak) _profile.keycloak = _null;
_profile.roleKeycloaks = [];
}
_profile.position = _null;
_profile.posTypeId = _null;
_profile.posLevelId = _null;
}
await Promise.all([
this.profileRepository.save(_profile),
this.salaryRepo.save(profileSalary),
]);
const history = new ProfileSalaryHistory();
Object.assign(history, { ...profileSalary, id: undefined });
history.profileSalaryId = profileSalary.id;
await this.salaryHistoryRepo.save(history);
}),
);
@ -2840,7 +2860,7 @@ export class CommandController extends Controller {
) {
const roleKeycloak = await this.roleKeycloakRepo.findOne({
where: { name: Like("USER") },
});
});
await Promise.all(
body.data.map(async (item) => {
const before = null;
@ -2870,7 +2890,7 @@ export class CommandController extends Controller {
let profile: any = await this.profileRepository.findOne({
where: { citizenId: item.bodyProfile.citizenId },
relations: ["roleKeycloaks"]
relations: ["roleKeycloaks"],
});
if (!profile) {
profile = Object.assign({ ...item.bodyProfile, ...meta });
@ -2903,7 +2923,7 @@ export class CommandController extends Controller {
);
if (!result) throw new Error("Failed. Cannot set user's role.");
profile.keycloak = userKeycloakId;
profile.roleKeycloaks = roleKeycloak ? [roleKeycloak] : []
profile.roleKeycloaks = roleKeycloak ? [roleKeycloak] : [];
profile.email = item.bodyProfile.email;
await this.profileRepository.save(profile);
setLogDataDiff(req, { before, after: profile });
@ -3061,7 +3081,7 @@ export class CommandController extends Controller {
await this.posMasterRepository.save(data);
if (posMasters && posMasters.length > 0) {
const orgRevision = await this.orgRevisionRepo.findOne({
where: { id: posMasters[0].orgRevisionId }
where: { id: posMasters[0].orgRevisionId },
});
if (orgRevision != null && orgRevision.isLock == false) {
await this.orgRevisionRepo.update(orgRevision.id, {
@ -3114,8 +3134,8 @@ export class CommandController extends Controller {
body.refIds.map(async (item) => {
const profile = await this.profileEmployeeRepository.findOne({
where: { id: item.refId },
relations: ["roleKeycloaks"]
})
relations: ["roleKeycloaks"],
});
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
@ -3172,7 +3192,7 @@ export class CommandController extends Controller {
},
});
if (posMasterOld != null) posMasterOld.current_holderId = null;
if (posMasterOld != null) posMasterOld.next_holderId = null;
// if (posMasterOld != null) posMasterOld.next_holderId = null;
const positionOld = await this.employeePositionRepository.findOne({
where: {
@ -3200,7 +3220,7 @@ export class CommandController extends Controller {
}
posMaster.current_holderId = profile.id;
posMaster.next_holderId = profile.id;
posMaster.next_holderId = null;
if (posMasterOld != null) await this.employeePosMasterRepository.save(posMasterOld);
await this.employeePosMasterRepository.save(posMaster);
@ -3212,7 +3232,6 @@ export class CommandController extends Controller {
});
if (positionNew != null) {
// Create Keycloak
const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
firstName: profile.firstName,
@ -3236,7 +3255,7 @@ export class CommandController extends Controller {
);
if (!result) throw new Error("Failed. Cannot set user's role.");
profile.keycloak = userKeycloakId;
profile.roleKeycloaks = roleKeycloak ? [roleKeycloak] : []
profile.roleKeycloaks = roleKeycloak ? [roleKeycloak] : [];
// End Create Keycloak
positionNew.positionIsSelected = true;
@ -3404,13 +3423,13 @@ export class CommandController extends Controller {
oc:
/*(posMasterAct.posMasterChild?.current_holder?.position ?? "-") +
"/" +*/
(_organization ?? "-"),
_organization ?? "-",
postype: posMasterAct.posMasterChild?.current_holder?.posType?.posTypeName ?? "-",
poslevel: posMasterAct.posMasterChild?.current_holder?.posLevel?.posLevelName ?? "-",
organizationNew:
/*(posMasterAct.posMaster?.current_holder?.position ?? "-") +
"/" +*/
(_organizationNew ?? "-"),
_organizationNew ?? "-",
// date: Extension.ToThaiShortDate_noPrefix(new Date()),
dateStart: "-",
dateEnd: "-",
@ -3483,7 +3502,7 @@ export class CommandController extends Controller {
posMasterId: posMaster.id,
positionIsSelected: true,
},
relations: ["posType", "posLevel"]
relations: ["posType", "posLevel"],
});
const dest_item = await this.salaryRepo.findOne({
where: { profileId: profile?.id },
@ -3567,10 +3586,13 @@ export class CommandController extends Controller {
const revisionId = data[0].orgRevisionId;
const orgRevision = await this.orgRevisionRepo.findOne({
where: { id: revisionId },
relations: ["posMasters"]
relations: ["posMasters"],
});
if (orgRevision != null && !["REPORT"].includes(
orgRevision.posMasters.find(x => x.statusReport === "REPORT")?.statusReport || "")
if (
orgRevision != null &&
!["REPORT"].includes(
orgRevision.posMasters.find((x) => x.statusReport === "REPORT")?.statusReport || "",
)
) {
await this.orgRevisionRepo.update(orgRevision.id, {
isLock: false,

View file

@ -2122,7 +2122,7 @@ export class EmployeePositionController extends Controller {
dataMaster.isSit = requestBody.isSit;
dataMaster.current_holderId = requestBody.profileId;
dataMaster.next_holderId = requestBody.profileId;
// dataMaster.next_holderId = requestBody.profileId;
await this.employeePosMasterRepository.save(dataMaster);
return new HttpSuccess();
@ -2242,7 +2242,7 @@ export class EmployeePositionController extends Controller {
},
});
if (posMasterOld != null) posMasterOld.current_holderId = null;
if (posMasterOld != null) posMasterOld.next_holderId = null;
// if (posMasterOld != null) posMasterOld.next_holderId = null;
const positionOld = await this.employeePositionRepository.findOne({
where: {
@ -2276,7 +2276,7 @@ export class EmployeePositionController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
posMaster.current_holderId = body.profileId;
posMaster.next_holderId = body.profileId;
// posMaster.next_holderId = body.profileId;
if (posMasterOld != null) await this.employeePosMasterRepository.save(posMasterOld);
await this.employeePosMasterRepository.save(posMaster);

View file

@ -41,6 +41,7 @@ import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
import { PosMasterAssign } from "../entities/PosMasterAssign";
import { Assign } from "../entities/Assign";
import { ProfileEmployee } from "../entities/ProfileEmployee";
@Route("api/v1/org/pos")
@Tags("Position")
@Security("bearerAuth")
@ -56,8 +57,10 @@ export class PositionController extends Controller {
private posLevelEmployeeRepository = AppDataSource.getRepository(EmployeePosLevel);
private posDictRepository = AppDataSource.getRepository(PosDict);
private posMasterRepository = AppDataSource.getRepository(PosMaster);
private employeePosMasterRepository = AppDataSource.getRepository(EmployeePosMaster);
private positionRepository = AppDataSource.getRepository(Position);
private profileRepository = AppDataSource.getRepository(Profile);
private profileEmployeeRepository = AppDataSource.getRepository(ProfileEmployee);
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
private child1Repository = AppDataSource.getRepository(OrgChild1);
@ -3587,6 +3590,7 @@ export class PositionController extends Controller {
.leftJoinAndSelect("positions.posType", "posType")
.leftJoinAndSelect("positions.posLevel", "posLevel")
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
.andWhere("posMaster.next_holderId IS NULL")
.andWhere(
new Brackets((qb) => {
qb.andWhere(typeCondition).andWhere(conditionA == null ? "1=1" : conditionA, {
@ -3841,6 +3845,7 @@ export class PositionController extends Controller {
.leftJoinAndSelect("positions.posType", "posType")
.leftJoinAndSelect("positions.posLevel", "posLevel")
// .leftJoinAndSelect("positions.posExecutive", "posExecutive")
.andWhere("posMaster.next_holderId IS NULL")
.andWhere(
new Brackets((qb) => {
qb.andWhere(typeCondition).andWhere(conditionA == null ? "1=1" : conditionA, {
@ -4799,4 +4804,218 @@ export class PositionController extends Controller {
await this.posMasterRepository.save(posMaster);
return new HttpSuccess();
}
/**
* API
*
* @summary (ADMIN)
*
*/
@Post("officer/master/book")
async posMasterBookOfficer(
@Body()
requestBody: {
posMasterId: string;
profileId: string;
},
@Request() request: RequestWithUser,
) {
const posMaster = await this.posMasterRepository.findOne({
where: { id: requestBody.posMasterId },
});
if (!posMaster) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง");
const profile = await this.profileRepository.findOne({
where: { id: requestBody.profileId },
});
if (!profile) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งาน");
posMaster.next_holderId = requestBody.profileId;
posMaster.lastUpdateUserId = request.user.sub;
posMaster.lastUpdateFullName = request.user.name;
posMaster.lastUpdatedAt = new Date();
await this.posMasterRepository.save(posMaster);
return new HttpSuccess();
}
/**
* API
*
* @summary (ADMIN)
*
*/
@Post("officer/master/clear")
async posMasterClearOfficer(
@Body()
requestBody: {
posMasterId: string;
},
@Request() request: RequestWithUser,
) {
const posMaster = await this.posMasterRepository.findOne({
where: { id: requestBody.posMasterId },
});
if (!posMaster) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง");
posMaster.next_holderId = null;
posMaster.lastUpdateUserId = request.user.sub;
posMaster.lastUpdateFullName = request.user.name;
posMaster.lastUpdatedAt = new Date();
await this.posMasterRepository.save(posMaster);
return new HttpSuccess();
}
/**
* API
*
* @summary (ADMIN)
*
*/
@Post("employee/master/book")
async posMasterBookEmployee(
@Body()
requestBody: {
posMasterId: string;
profileId: string;
},
@Request() request: RequestWithUser,
) {
const posMaster = await this.employeePosMasterRepository.findOne({
where: { id: requestBody.posMasterId },
});
if (!posMaster) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง");
const profile = await this.profileEmployeeRepository.findOne({
where: { id: requestBody.profileId },
});
if (!profile) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งาน");
posMaster.next_holderId = requestBody.profileId;
posMaster.lastUpdateUserId = request.user.sub;
posMaster.lastUpdateFullName = request.user.name;
posMaster.lastUpdatedAt = new Date();
await this.employeePosMasterRepository.save(posMaster);
return new HttpSuccess();
}
/**
* API
*
* @summary (ADMIN)
*
*/
@Post("employee/master/clear")
async posMasterClearEmployee(
@Body()
requestBody: {
posMasterId: string;
},
@Request() request: RequestWithUser,
) {
const posMaster = await this.employeePosMasterRepository.findOne({
where: { id: requestBody.posMasterId },
});
if (!posMaster) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง");
posMaster.next_holderId = null;
posMaster.lastUpdateUserId = request.user.sub;
posMaster.lastUpdateFullName = request.user.name;
posMaster.lastUpdatedAt = new Date();
await this.employeePosMasterRepository.save(posMaster);
return new HttpSuccess();
}
/**
* API
*
* @summary (ADMIN)
*
*/
@Post("officer/master-old/book")
async posMasterOldBookOfficer(
@Body()
requestBody: {
posMasterId: string;
posMasterOldId: string;
profileId: string;
},
@Request() request: RequestWithUser,
) {
const posMaster = await this.posMasterRepository.findOne({
where: { id: requestBody.posMasterId },
});
if (!posMaster) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง");
const profile = await this.profileRepository.findOne({
where: { id: requestBody.profileId },
});
if (!profile) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งาน");
posMaster.next_holderId = requestBody.profileId;
posMaster.lastUpdateUserId = request.user.sub;
posMaster.lastUpdateFullName = request.user.name;
posMaster.lastUpdatedAt = new Date();
await this.posMasterRepository.save(posMaster);
if (requestBody.posMasterOldId != null) {
const posMasterOld = await this.posMasterRepository.findOne({
where: { id: requestBody.posMasterOldId },
});
if (!posMasterOld) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง");
posMasterOld.next_holderId = null;
posMasterOld.lastUpdateUserId = request.user.sub;
posMasterOld.lastUpdateFullName = request.user.name;
posMasterOld.lastUpdatedAt = new Date();
await this.posMasterRepository.save(posMasterOld);
}
return new HttpSuccess();
}
/**
* API
*
* @summary (ADMIN)
*
*/
@Post("employee/master-old/book")
async posMasterOldBookEmployee(
@Body()
requestBody: {
posMasterId: string;
posMasterOldId: string;
profileId: string;
},
@Request() request: RequestWithUser,
) {
const posMaster = await this.employeePosMasterRepository.findOne({
where: { id: requestBody.posMasterId },
});
if (!posMaster) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง");
const profile = await this.profileEmployeeRepository.findOne({
where: { id: requestBody.profileId },
});
if (!profile) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งาน");
posMaster.next_holderId = requestBody.profileId;
posMaster.lastUpdateUserId = request.user.sub;
posMaster.lastUpdateFullName = request.user.name;
posMaster.lastUpdatedAt = new Date();
await this.employeePosMasterRepository.save(posMaster);
if (requestBody.posMasterOldId != null) {
const posMasterOld = await this.employeePosMasterRepository.findOne({
where: { id: requestBody.posMasterOldId },
});
if (!posMasterOld) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง");
posMasterOld.next_holderId = null;
posMasterOld.lastUpdateUserId = request.user.sub;
posMasterOld.lastUpdateFullName = request.user.name;
posMasterOld.lastUpdatedAt = new Date();
await this.employeePosMasterRepository.save(posMasterOld);
}
return new HttpSuccess();
}
}

View file

@ -231,20 +231,23 @@ export class ProfileEmployeeController extends Controller {
where: { profileEmployeeId: id },
order: { lastUpdatedAt: "DESC" },
});
const Education = educations && educations.length > 0
? educations.map((item) => ({
institute: item.institute ? item.institute : "-",
date:
item.startDate && item.endDate
? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}`
: "-",
degree: item.degree && item.field ? `${item.degree} ${item.field}` : "-",
}))
: [{
institute: "-",
date: "-",
degree: "-",
}]
const Education =
educations && educations.length > 0
? educations.map((item) => ({
institute: item.institute ? item.institute : "-",
date:
item.startDate && item.endDate
? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}`
: "-",
degree: item.degree && item.field ? `${item.degree} ${item.field}` : "-",
}))
: [
{
institute: "-",
date: "-",
degree: "-",
},
];
const mapData = {
// Id: profile.id,
@ -1985,8 +1988,7 @@ export class ProfileEmployeeController extends Controller {
child4ShortName: child4 == null ? null : child4.orgChild4ShortName,
node: null,
nodeId: null,
salary:
profile && profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null,
salary: profile && profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null,
};
return new HttpSuccess(_profile);
}
@ -3856,15 +3858,15 @@ export class ProfileEmployeeController extends Controller {
"current_holders.orgChild3",
"current_holders.orgChild4",
"profileSalary",
"profileEducations"
"profileEducations",
],
order: {
// profileSalary: {
// order: "DESC",
// },
profileEducations: {
createdAt: "DESC"
}
createdAt: "DESC",
},
},
});
if (!profile) {
@ -3986,11 +3988,11 @@ export class ProfileEmployeeController extends Controller {
node: null,
nodeId: null,
posNo: shortName,
salary:
profile && profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null,
education: profile && profile.profileEducations.length > 0
? `${profile.profileEducations[0].degree ?? ""}-${profile.profileEducations[0].field ?? ""}`
: "-"
salary: profile && profile.profileSalary.length > 0 ? profile.profileSalary[0].amount : null,
education:
profile && profile.profileEducations.length > 0
? `${profile.profileEducations[0].degree ?? ""}-${profile.profileEducations[0].field ?? ""}`
: "-",
};
if (_profile.child4Id != null) {