Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2024-10-25 15:52:58 +07:00
commit 22aefabec1
4 changed files with 380 additions and 260 deletions

View file

@ -39,6 +39,7 @@ import {
commandTypePath, commandTypePath,
removeProfileInOrganize, removeProfileInOrganize,
setLogDataDiff, setLogDataDiff,
checkCommandType
} from "../interfaces/utils"; } from "../interfaces/utils";
import { Position } from "../entities/Position"; import { Position } from "../entities/Position";
import { PosMaster } from "../entities/PosMaster"; import { PosMaster } from "../entities/PosMaster";
@ -50,7 +51,7 @@ import { PosMasterAct } from "../entities/PosMasterAct";
import { sendToQueue } from "../services/rabbitmq"; import { sendToQueue } from "../services/rabbitmq";
import { PosLevel } from "../entities/PosLevel"; import { PosLevel } from "../entities/PosLevel";
import { PosType } from "../entities/PosType"; import { PosType } from "../entities/PosType";
import { addUserRoles, createUser, getRoles } from "../keycloak"; import { addUserRoles, createUser, getRoles, deleteUser } from "../keycloak";
import { ProfileEducation, CreateProfileEducation } from "../entities/ProfileEducation"; import { ProfileEducation, CreateProfileEducation } from "../entities/ProfileEducation";
import { ProfileEducationHistory } from "../entities/ProfileEducationHistory"; import { ProfileEducationHistory } from "../entities/ProfileEducationHistory";
import { CreateProfileCertificate, ProfileCertificate } from "../entities/ProfileCertificate"; import { CreateProfileCertificate, ProfileCertificate } from "../entities/ProfileCertificate";
@ -1826,6 +1827,16 @@ export class CommandController extends Controller {
if (item.isLeave == true) { if (item.isLeave == true) {
await removeProfileInOrganize(profile.id, "OFFICER"); await removeProfileInOrganize(profile.id, "OFFICER");
} }
const clearProfile = await checkCommandType(String(item.commandId));
if(clearProfile) {
if(profile.keycloak != null) {
const delUserKeycloak = await deleteUser(profile.keycloak);
if (delUserKeycloak) profile.keycloak = _null;
}
profile.position = _null;
profile.posTypeId = _null;
profile.posLevelId = _null;
}
await this.profileRepository.save(profile); await this.profileRepository.save(profile);
}), }),
); );
@ -1854,6 +1865,7 @@ export class CommandController extends Controller {
leaveReason?: string | null; leaveReason?: string | null;
dateLeave?: Date | null; dateLeave?: Date | null;
isGovernment?: boolean | null; isGovernment?: boolean | null;
commandId?: string | null;
}[]; }[];
}, },
) { ) {
@ -1905,6 +1917,16 @@ export class CommandController extends Controller {
if (item.isLeave == true) { if (item.isLeave == true) {
await removeProfileInOrganize(profile.id, "EMPLOYEE"); await removeProfileInOrganize(profile.id, "EMPLOYEE");
} }
const clearProfile = await checkCommandType(String(item.commandId));
if(clearProfile) {
if(profile.keycloak != null) {
const delUserKeycloak = await deleteUser(profile.keycloak);
if (delUserKeycloak) profile.keycloak = _null;
}
profile.position = _null;
profile.posTypeId = _null;
profile.posLevelId = _null;
}
await this.profileEmployeeRepository.save(profile); await this.profileEmployeeRepository.save(profile);
}), }),
); );
@ -1959,7 +1981,18 @@ export class CommandController extends Controller {
createdAt: new Date(), createdAt: new Date(),
lastUpdatedAt: new Date(), lastUpdatedAt: new Date(),
}; };
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.position = _null;
profile.posTypeId = _null;
profile.posLevelId = _null;
await this.profileRepository.save(profile, {data: req});
}
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 });
@ -2155,6 +2188,16 @@ export class CommandController extends Controller {
if (item.isLeave == true) { if (item.isLeave == true) {
await removeProfileInOrganize(profile.id, "OFFICER"); await removeProfileInOrganize(profile.id, "OFFICER");
} }
const clearProfile = await checkCommandType(String(item.commandId));
if(clearProfile) {
if(profile.keycloak != null) {
const delUserKeycloak = await deleteUser(profile.keycloak);
if (delUserKeycloak) profile.keycloak = _null;
}
profile.position = _null;
profile.posTypeId = _null;
profile.posLevelId = _null;
}
await this.profileRepository.save(profile); await this.profileRepository.save(profile);
} }
}), }),
@ -2327,6 +2370,17 @@ export class CommandController extends Controller {
dateGovernment: new Date(), dateGovernment: new Date(),
isGovernment: item.isGovernment, isGovernment: item.isGovernment,
}); });
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.position = _null;
_profile.posTypeId = _null;
_profile.posLevelId = _null;
}
await Promise.all([ await Promise.all([
this.profileRepository.save(_profile), this.profileRepository.save(_profile),
this.salaryRepo.save(profileSalary), this.salaryRepo.save(profileSalary),

View file

@ -5212,6 +5212,56 @@ export class ProfileController extends Controller {
? null ? null
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) : item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild4?.orgChild4Name, ?.orgChild4?.orgChild4Name,
root:
item.current_holders == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgRoot ==
null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgRoot
?.orgRootName == null
? null
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgRoot
?.id,
orgChild1:
item.current_holders == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild1 ==
null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild1
?.orgChild1Name == null
? null
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild1?.id,
orgChild2:
item.current_holders == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild2 ==
null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild2
?.orgChild2Name == null
? null
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild2?.id,
orgChild3:
item.current_holders == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild3 ==
null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild3
?.orgChild3Name == null
? null
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild3?.id,
orgChild4:
item.current_holders == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) == null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild4 ==
null ||
item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild4
?.orgChild4Name == null
? null
: item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild4?.id,
}; };
}), }),
); );
@ -6566,78 +6616,78 @@ export class ProfileController extends Controller {
return new HttpSuccess(); return new HttpSuccess();
} }
/** /**
* API * API
* *
* @summary ORG_065 - * @summary ORG_065 -
* *
*/ */
@Get("otherSystem") @Get("otherSystem")
@Example({ @Example({
status: 200, status: 200,
message: "สำเร็จ", message: "สำเร็จ",
result: { result: {
data: [ data: [
{ {
id: "ecb0b34c-037e-41f2-b95e-7e19f88b42ae", id: "ecb0b34c-037e-41f2-b95e-7e19f88b42ae",
createdAt: "2024-03-24T12:39:12.105Z", createdAt: "2024-03-24T12:39:12.105Z",
createdUserId: "00000000-0000-0000-0000-000000000000", createdUserId: "00000000-0000-0000-0000-000000000000",
lastUpdatedAt: "2024-03-24T12:41:43.164Z", lastUpdatedAt: "2024-03-24T12:41:43.164Z",
lastUpdateUserId: "00000000-0000-0000-0000-000000000000", lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
createdFullName: "string", createdFullName: "string",
lastUpdateFullName: "string", lastUpdateFullName: "string",
rank: null, rank: null,
prefix: null, prefix: null,
firstName: "Methapon", firstName: "Methapon",
lastName: "Metanipat", lastName: "Metanipat",
citizenId: null, citizenId: null,
position: null, position: null,
posLevelId: null, posLevelId: null,
posTypeId: null, posTypeId: null,
email: null, email: null,
phone: null, phone: null,
keycloak: null, keycloak: null,
isProbation: false, isProbation: false,
dateRetire: null, dateRetire: null,
birthDate: null, birthDate: null,
ethnicity: null, ethnicity: null,
telephoneNumber: null, telephoneNumber: null,
gender: null, gender: null,
relationship: null, relationship: null,
bloodGroup: null, bloodGroup: null,
posLevel: null, posLevel: null,
posType: null, posType: null,
org: null, org: null,
}, },
], ],
total: 1, total: 1,
}, },
}) })
async listProfileNoPermission( async listProfileNoPermission(
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
@Query("page") page: number = 1, @Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query() @Query()
searchField?: "firstName" | "lastName" | "fullName" | "citizenId" | "position" | "posNo", searchField?: "firstName" | "lastName" | "fullName" | "citizenId" | "position" | "posNo",
@Query() searchKeyword: string = "", @Query() searchKeyword: string = "",
@Query() posType?: string, @Query() posType?: string,
@Query() posLevel?: string, @Query() posLevel?: string,
@Query() yearLeave?: number, @Query() yearLeave?: number,
@Query() isProbation?: boolean, @Query() isProbation?: boolean,
@Query() isRetire?: boolean, @Query() isRetire?: boolean,
@Query() node?: number, @Query() node?: number,
@Query() nodeId?: string, @Query() nodeId?: string,
@Query() isAll?: boolean, @Query() isAll?: boolean,
) { ) {
// let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER"); // let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER");
let queryLike = let queryLike =
"CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword"; "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword";
if (searchField == "citizenId") { if (searchField == "citizenId") {
queryLike = "profile.citizenId LIKE :keyword"; queryLike = "profile.citizenId LIKE :keyword";
} else if (searchField == "position") { } else if (searchField == "position") {
queryLike = "profile.position LIKE :keyword"; queryLike = "profile.position LIKE :keyword";
} else if (searchField == "posNo") { } else if (searchField == "posNo") {
queryLike = `CONCAT( queryLike = `CONCAT(
IFNULL(orgChild4.orgChild4ShortName, ''), IFNULL(orgChild4.orgChild4ShortName, ''),
IFNULL(orgChild3.orgChild3ShortName, ''), IFNULL(orgChild3.orgChild3ShortName, ''),
IFNULL(orgChild2.orgChild2ShortName, ''), IFNULL(orgChild2.orgChild2ShortName, ''),
@ -6645,37 +6695,37 @@ export class ProfileController extends Controller {
IFNULL(orgRoot.orgRootShortName, ''), IFNULL(orgRoot.orgRootShortName, ''),
IFNULL(current_holders.posMasterNo , '') IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword`; ) LIKE :keyword`;
} }
let nodeCondition = "1=1"; let nodeCondition = "1=1";
let nodeAll = ""; let nodeAll = "";
if (node === 0 && nodeId) { if (node === 0 && nodeId) {
nodeCondition = "current_holders.orgRootId = :nodeId"; nodeCondition = "current_holders.orgRootId = :nodeId";
if (isAll == false) nodeAll = " AND current_holders.orgChild1Id IS NULL"; if (isAll == false) nodeAll = " AND current_holders.orgChild1Id IS NULL";
} else if (node === 1 && nodeId) { } else if (node === 1 && nodeId) {
nodeCondition = "current_holders.orgChild1Id = :nodeId"; nodeCondition = "current_holders.orgChild1Id = :nodeId";
if (isAll == false) nodeAll = " AND current_holders.orgChild2Id IS NULL"; if (isAll == false) nodeAll = " AND current_holders.orgChild2Id IS NULL";
} else if (node === 2 && nodeId) { } else if (node === 2 && nodeId) {
nodeCondition = "current_holders.orgChild2Id = :nodeId"; nodeCondition = "current_holders.orgChild2Id = :nodeId";
if (isAll == false) nodeAll = " AND current_holders.orgChild3Id IS NULL"; if (isAll == false) nodeAll = " AND current_holders.orgChild3Id IS NULL";
} else if (node === 3 && nodeId) { } else if (node === 3 && nodeId) {
nodeCondition = "current_holders.orgChild3Id = :nodeId"; nodeCondition = "current_holders.orgChild3Id = :nodeId";
if (isAll == false) nodeAll = " AND current_holders.orgChild4Id IS NULL"; if (isAll == false) nodeAll = " AND current_holders.orgChild4Id IS NULL";
} else if (node === 4 && nodeId) { } else if (node === 4 && nodeId) {
nodeCondition = "current_holders.orgChild4Id = :nodeId"; nodeCondition = "current_holders.orgChild4Id = :nodeId";
} }
nodeCondition = nodeCondition + nodeAll; nodeCondition = nodeCondition + nodeAll;
const [record, total] = await this.profileRepo const [record, total] = await this.profileRepo
.createQueryBuilder("profile") .createQueryBuilder("profile")
.leftJoinAndSelect("profile.posLevel", "posLevel") .leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType") .leftJoinAndSelect("profile.posType", "posType")
.leftJoinAndSelect("profile.current_holders", "current_holders") .leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("current_holders.positions", "positions") .leftJoinAndSelect("current_holders.positions", "positions")
.leftJoinAndSelect("positions.posExecutive", "posExecutive") .leftJoinAndSelect("positions.posExecutive", "posExecutive")
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot") .leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1") .leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2") .leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3") .leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4") .leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
// .andWhere( // .andWhere(
// _data.root != undefined && _data.root != null // _data.root != undefined && _data.root != null
// ? _data.root[0] != null // ? _data.root[0] != null
@ -6726,164 +6776,164 @@ export class ProfileController extends Controller {
// child4: _data.child4, // child4: _data.child4,
// }, // },
// ) // )
.andWhere( .andWhere(
posType != undefined && posType != null && posType != "" posType != undefined && posType != null && posType != ""
? "posType.posTypeName LIKE :keyword1" ? "posType.posTypeName LIKE :keyword1"
: "1=1", : "1=1",
{ {
keyword1: `${posType}`, keyword1: `${posType}`,
}, },
) )
.andWhere( .andWhere(
posLevel != undefined && posLevel != null && posLevel != "" posLevel != undefined && posLevel != null && posLevel != ""
? "posLevel.posLevelName LIKE :keyword2" ? "posLevel.posLevelName LIKE :keyword2"
: "1=1", : "1=1",
{ {
keyword2: `${posLevel}`, keyword2: `${posLevel}`,
}, },
) )
.andWhere( .andWhere(
isProbation != undefined && isProbation != null isProbation != undefined && isProbation != null
? `profile.isProbation = ${isProbation}` ? `profile.isProbation = ${isProbation}`
: "1=1", : "1=1",
) )
.andWhere( .andWhere(
isRetire != undefined && isRetire != null isRetire != undefined && isRetire != null
? isRetire == false ? isRetire == false
? `profile.dateLeave IS null` ? `profile.dateLeave IS null`
: `profile.dateLeave IS NOT NULL` : `profile.dateLeave IS NOT NULL`
: "1=1", : "1=1",
) )
.andWhere( .andWhere(
searchKeyword != undefined && searchKeyword != null && searchKeyword != "" searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
? queryLike ? queryLike
: "1=1", : "1=1",
{ {
keyword: `%${searchKeyword}%`, keyword: `%${searchKeyword}%`,
}, },
) )
.andWhere(nodeCondition, { .andWhere(nodeCondition, {
nodeId: nodeId, nodeId: nodeId,
}) })
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
.take(pageSize) .take(pageSize)
.getManyAndCount(); .getManyAndCount();
const findRevision = await this.orgRevisionRepo.findOne({ const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true }, where: { orgRevisionIsCurrent: true },
}); });
if (!findRevision) { if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
} }
const data = await Promise.all( const data = await Promise.all(
record.map((_data) => { record.map((_data) => {
const posExecutive = const posExecutive =
_data.current_holders.length == 0 || _data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null || _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.positions.length == _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.positions.length ==
0 || 0 ||
_data.current_holders _data.current_holders
.find((x) => x.orgRevisionId == findRevision.id) .find((x) => x.orgRevisionId == findRevision.id)
?.positions.find((x: any) => x.positionIsSelected == true) == null || ?.positions.find((x: any) => x.positionIsSelected == true) == null ||
_data.current_holders _data.current_holders
.find((x) => x.orgRevisionId == findRevision.id) .find((x) => x.orgRevisionId == findRevision.id)
?.positions.find((x: any) => x.positionIsSelected == true)?.posExecutive == null ?.positions.find((x: any) => x.positionIsSelected == true)?.posExecutive == null
? null ? null
: _data.current_holders : _data.current_holders
.find((x) => x.orgRevisionId == findRevision.id) .find((x) => x.orgRevisionId == findRevision.id)
?.positions.find((x: any) => x.positionIsSelected == true)?.posExecutive ?.positions.find((x: any) => x.positionIsSelected == true)?.posExecutive
?.posExecutiveName; ?.posExecutiveName;
const shortName = const shortName =
_data.current_holders.length == 0 _data.current_holders.length == 0
? null ? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 != _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 !=
null null
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild3 != null ?.orgChild3 != null
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild2 != null ?.orgChild2 != null
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild1 != null ?.orgChild1 != null
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) !=
null && null &&
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgRoot != null ?.orgRoot != null
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` ? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: null; : null;
const root = const root =
_data.current_holders.length == 0 || _data.current_holders.length == 0 ||
(_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && (_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null &&
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null) _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null)
? null ? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot; : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
const child1 = const child1 =
_data.current_holders == null || _data.current_holders == null ||
_data.current_holders.length == 0 || _data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null ? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1; : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1;
const child2 = const child2 =
_data.current_holders == null || _data.current_holders == null ||
_data.current_holders.length == 0 || _data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null ? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2; : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2;
const child3 = const child3 =
_data.current_holders == null || _data.current_holders == null ||
_data.current_holders.length == 0 || _data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null ? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3; : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3;
const child4 = const child4 =
_data.current_holders == null || _data.current_holders == null ||
_data.current_holders.length == 0 || _data.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null ? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4; : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4;
let _child1 = child1 == null ? "" : `${child1.orgChild1Name}/`; let _child1 = child1 == null ? "" : `${child1.orgChild1Name}/`;
let _child2 = child2 == null ? "" : `${child2.orgChild2Name}/`; let _child2 = child2 == null ? "" : `${child2.orgChild2Name}/`;
let _child3 = child3 == null ? "" : `${child3.orgChild3Name}/`; let _child3 = child3 == null ? "" : `${child3.orgChild3Name}/`;
let _child4 = child4 == null ? "" : `${child4.orgChild4Name}/`; let _child4 = child4 == null ? "" : `${child4.orgChild4Name}/`;
return { return {
id: _data.id, id: _data.id,
avatar: _data.avatar, avatar: _data.avatar,
avatarName: _data.avatarName, avatarName: _data.avatarName,
prefix: _data.prefix, prefix: _data.prefix,
rank: _data.rank, rank: _data.rank,
firstName: _data.firstName, firstName: _data.firstName,
lastName: _data.lastName, lastName: _data.lastName,
citizenId: _data.citizenId, citizenId: _data.citizenId,
posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName, posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName,
posType: _data.posType == null ? null : _data.posType.posTypeName, posType: _data.posType == null ? null : _data.posType.posTypeName,
posLevelId: _data.posLevel == null ? null : _data.posLevel.id, posLevelId: _data.posLevel == null ? null : _data.posLevel.id,
posTypeId: _data.posType == null ? null : _data.posType.id, posTypeId: _data.posType == null ? null : _data.posType.id,
position: _data.position, position: _data.position,
posExecutive: posExecutive, posExecutive: posExecutive,
posNo: shortName, posNo: shortName,
rootId: root == null ? null : root.id, rootId: root == null ? null : root.id,
root: root == null ? null : root.orgRootName, root: root == null ? null : root.orgRootName,
orgRootShortName: root == null ? null : root.orgRootShortName, orgRootShortName: root == null ? null : root.orgRootShortName,
orgRevisionId: root == null ? null : root.orgRevisionId, orgRevisionId: root == null ? null : root.orgRevisionId,
org: `${_child4}${_child3}${_child2}${_child1}${root?.orgRootName ?? ""}`, org: `${_child4}${_child3}${_child2}${_child1}${root?.orgRootName ?? ""}`,
}; };
}), }),
); );
return new HttpSuccess({ data: data, total }); return new HttpSuccess({ data: data, total });
} }
} }

View file

@ -187,7 +187,7 @@ export class KeycloakController extends Controller {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
where: { where: {
id: userId, keycloak: userId,
}, },
}); });

View file

@ -6,6 +6,7 @@ import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { EmployeePosition } from "../entities/EmployeePosition"; import { EmployeePosition } from "../entities/EmployeePosition";
import { In } from "typeorm"; import { In } from "typeorm";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { Command } from "../entities/Command";
export function calculateAge(start: Date, end = new Date()) { export function calculateAge(start: Date, end = new Date()) {
if (start.getTime() > end.getTime()) return null; if (start.getTime() > end.getTime()) return null;
@ -173,6 +174,21 @@ export async function removeProfileInOrganize(profileId: string, type: string) {
.execute(); .execute();
} }
} }
export async function checkCommandType(commandId: string) {
const commandRepository = AppDataSource.getRepository(Command);
const _type = await commandRepository.findOne({
where: {
id: commandId
},
relations: ["commandType"],
});
if (!["C-PM-12", "C-PM-13", "C-PM-17", "C-PM-18", "C-PM-23", "C-PM-19", "C-PM-20"].includes(String(_type?.commandType.code))) {
return false;
}
return true;
}
//logs //logs
export type DataDiff = { export type DataDiff = {
before: any; before: any;