Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2024-12-13 15:48:08 +07:00
commit 94134355fa
11 changed files with 801 additions and 247 deletions

102
.onedev-buildspec.yml Normal file
View file

@ -0,0 +1,102 @@
version: 37
jobs:
- name: CI for UAT
steps:
- !CheckoutStep
name: checkout code
cloneCredential: !DefaultCredential {}
withLfs: false
withSubmodules: false
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !GenerateChecksumStep
name: generate package checksum
files: package-lock.json yarn.lock
targetFile: checksum
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !SetupCacheStep
name: set up npm cache
key: node_modules_@file:checksum@
loadKeys:
- node_modules
paths:
- node_modules
uploadStrategy: UPLOAD_IF_NOT_HIT
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !SetBuildVersionStep
name: set build version
buildVersion: '@tag@'
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !CommandStep
name: build & test
runInContainer: true
image: node
interpreter: !DefaultInterpreter
commands: |
npm install
npm run build
useTTY: true
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !BuildImageStep
name: build docker image
dockerfile: ./docker/Dockerfile
output: !RegistryOutput
tags: hrms-git.chin.in.th/bma-hrms/hrms-api-org:@build_version@ hrms-git.chin.in.th/bma-hrms/hrms-api-org:latest
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
triggers:
- !TagCreateTrigger
tags: uat-*
branches: main
retryCondition: never
maxRetries: 3
retryDelay: 30
timeout: 14400
- name: CI for PROD
steps:
- !CheckoutStep
name: checkout code
cloneCredential: !DefaultCredential {}
withLfs: false
withSubmodules: false
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !GenerateChecksumStep
name: generate package checksum
files: package-lock.json yarn.lock
targetFile: checksum
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !SetupCacheStep
name: set up npm cache
key: node_modules_@file:checksum@
loadKeys:
- node_modules
paths:
- node_modules
uploadStrategy: UPLOAD_IF_NOT_HIT
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !SetBuildVersionStep
name: set build version
buildVersion: '@tag@'
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !CommandStep
name: build & test
runInContainer: true
image: node
interpreter: !DefaultInterpreter
commands: |
npm install
npm run build
useTTY: true
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !BuildImageStep
name: build docker image
dockerfile: ./docker/Dockerfile
output: !RegistryOutput
tags: hrms-git.bangkok.go.th/bma-hrms/hrms-api-org:@build_version@ hrms-git.bangkok.go.th/bma-hrms/hrms-api-org:latest
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
triggers:
- !TagCreateTrigger
tags: prod-*
branches: main
retryCondition: never
maxRetries: 3
retryDelay: 30
timeout: 14400

View file

@ -943,7 +943,7 @@ export class CommandController extends Controller {
await new permission().PermissionGet(request, "COMMAND"); await new permission().PermissionGet(request, "COMMAND");
const command = await this.commandRepository.findOne({ const command = await this.commandRepository.findOne({
where: { id }, where: { id },
relations: ["commandType"] relations: ["commandType"],
}); });
if (!command) { if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -1165,7 +1165,7 @@ export class CommandController extends Controller {
await new permission().PermissionUpdate(request, "COMMAND"); await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({ const command = await this.commandRepository.findOne({
where: { id: id }, where: { id: id },
relations: ["commandType", "commandRecives",], relations: ["commandType", "commandRecives"],
}); });
if (!command) { if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -1255,7 +1255,7 @@ export class CommandController extends Controller {
let _data: any = null; let _data: any = null;
await Promise.all([ await Promise.all([
await new CallAPI() await new CallAPI()
.PostDataKeycloak("/realms/bma-ehr/protocol/openid-connect/token", data) .PostDataKeycloak(`/realms/${process.env.KC_REALM}/protocol/openid-connect/token`, data)
.then(async (x) => { .then(async (x) => {
_data = x; _data = x;
}) })
@ -2265,16 +2265,22 @@ export class CommandController extends Controller {
lastName: profile.lastName, lastName: profile.lastName,
}); });
// กรณี Keycloak ไม่ถูกลบ ให้ลบซ้ำอีกรอบแล้วสร้างใหม่ และหากยังไม่สามารถลบได้ให้แสดง Error // กรณี Keycloak ไม่ถูกลบ ให้ลบซ้ำอีกรอบแล้วสร้างใหม่ และหากยังไม่สามารถลบได้ให้แสดง Error
if (profile.keycloak != null && userKeycloakId && userKeycloakId.errorMessage === "User exists with same username") { if (
profile.keycloak != null &&
userKeycloakId &&
userKeycloakId.errorMessage === "User exists with same username"
) {
const delUserKeycloak = await deleteUser(profile.keycloak); const delUserKeycloak = await deleteUser(profile.keycloak);
if (delUserKeycloak) { if (delUserKeycloak) {
userKeycloakId = await createUser(profile.citizenId, profile.citizenId, { userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
firstName: profile.firstName, firstName: profile.firstName,
lastName: profile.lastName, lastName: profile.lastName,
}); });
} } else {
else { throw new HttpError(
throw new HttpError(HttpStatus.BAD_REQUEST, "พบข้อผิดพลาด ไม่สามารถจัดการผู้ใช้งานได้"); HttpStatus.BAD_REQUEST,
"พบข้อผิดพลาด ไม่สามารถจัดการผู้ใช้งานได้",
);
} }
} }
const list = await getRoles(); const list = await getRoles();
@ -3468,6 +3474,7 @@ export class CommandController extends Controller {
const _null: any = null; const _null: any = null;
profile.employeeWage = item.amount == null ? _null : item.amount.toString(); profile.employeeWage = item.amount == null ? _null : item.amount.toString();
profile.dateStart = new Date(); profile.dateStart = new Date();
profile.dateAppoint = new Date();
profile.amount = item.amount == null ? _null : item.amount; profile.amount = item.amount == null ? _null : item.amount;
profile.amountSpecial = item.amountSpecial == null ? _null : item.amountSpecial; profile.amountSpecial = item.amountSpecial == null ? _null : item.amountSpecial;
@ -3792,7 +3799,9 @@ export class CommandController extends Controller {
if ( if (
orgRevision != null && orgRevision != null &&
!["REPORT", "DONE"].includes( !["REPORT", "DONE"].includes(
orgRevision.posMasters.find((x) => x.statusReport === "REPORT" || x.statusReport === "DONE")?.statusReport || "", orgRevision.posMasters.find(
(x) => x.statusReport === "REPORT" || x.statusReport === "DONE",
)?.statusReport || "",
) )
) { ) {
await this.orgRevisionRepo.update(orgRevision.id, { await this.orgRevisionRepo.update(orgRevision.id, {

View file

@ -37,16 +37,16 @@ export class LoginController extends Controller {
let _data: any = null; let _data: any = null;
await Promise.all([ await Promise.all([
await new CallAPI() await new CallAPI()
.PostDataKeycloak("/realms/bma-ehr/protocol/openid-connect/token", data) .PostDataKeycloak(`/realms/${process.env.KC_REALM}/protocol/openid-connect/token`, data)
.then(async (x) => { .then(async (x) => {
_data = x; _data = x;
}) })
.catch(async (x) => { .catch(async (x) => {
throw new HttpError(HttpStatus.UNAUTHORIZED, "ชื่อผู้ใช้งานหรือรหัสผ่านไม่ถูกต้อง"); throw new HttpError(HttpStatus.UNAUTHORIZED, "ชื่อผู้ใช้งานหรือรหัสผ่านไม่ถูกต้อง4");
}), }),
]); ]);
if (_data == null) { if (_data == null) {
return new HttpError(HttpStatus.UNAUTHORIZED, "ชื่อผู้ใช้งานหรือรหัสผ่านไม่ถูกต้อง"); return new HttpError(HttpStatus.UNAUTHORIZED, "ชื่อผู้ใช้งานหรือรหัสผ่านไม่ถูกต้อง5");
} else { } else {
return new HttpSuccess(_data); return new HttpSuccess(_data);
} }

View file

@ -2663,7 +2663,9 @@ export class OrganizationController extends Controller {
orgRoot.orgRootCode + orgRoot.orgRootCode +
orgChild1.orgChild1Code + orgChild1.orgChild1Code +
" " + " " +
orgChild1.orgChild1ShortName, orgChild1.orgChild1ShortName +
"/" +
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
totalPosition: await this.posMasterRepository.count({ totalPosition: await this.posMasterRepository.count({
where: { orgRevisionId: orgRoot.orgRevisionId, orgChild1Id: orgChild1.id }, where: { orgRevisionId: orgRoot.orgRevisionId, orgChild1Id: orgChild1.id },
}), }),
@ -2778,7 +2780,16 @@ export class OrganizationController extends Controller {
orgRoot.orgRootCode + orgRoot.orgRootCode +
orgChild2.orgChild2Code + orgChild2.orgChild2Code +
" " + " " +
orgChild2.orgChild2ShortName, orgChild2.orgChild2ShortName +
"/" +
orgChild1.orgChild1Name +
" " +
orgRoot.orgRootCode +
orgChild1.orgChild1Code +
" " +
orgChild1.orgChild1ShortName +
"/" +
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
totalPosition: await this.posMasterRepository.count({ totalPosition: await this.posMasterRepository.count({
where: { where: {
orgRevisionId: orgRoot.orgRevisionId, orgRevisionId: orgRoot.orgRevisionId,
@ -2896,7 +2907,23 @@ export class OrganizationController extends Controller {
orgRoot.orgRootCode + orgRoot.orgRootCode +
orgChild3.orgChild3Code + orgChild3.orgChild3Code +
" " + " " +
orgChild3.orgChild3ShortName, orgChild3.orgChild3ShortName +
"/" +
orgChild2.orgChild2Name +
" " +
orgRoot.orgRootCode +
orgChild2.orgChild2Code +
" " +
orgChild2.orgChild2ShortName +
"/" +
orgChild1.orgChild1Name +
" " +
orgRoot.orgRootCode +
orgChild1.orgChild1Code +
" " +
orgChild1.orgChild1ShortName +
"/" +
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
totalPosition: await this.posMasterRepository.count({ totalPosition: await this.posMasterRepository.count({
where: { where: {
orgRevisionId: orgRoot.orgRevisionId, orgRevisionId: orgRoot.orgRevisionId,
@ -3014,7 +3041,30 @@ export class OrganizationController extends Controller {
orgRoot.orgRootCode + orgRoot.orgRootCode +
orgChild4.orgChild4Code + orgChild4.orgChild4Code +
" " + " " +
orgChild4.orgChild4ShortName, orgChild4.orgChild4ShortName +
"/" +
orgChild3.orgChild3Name +
" " +
orgRoot.orgRootCode +
orgChild3.orgChild3Code +
" " +
orgChild3.orgChild3ShortName +
"/" +
orgChild2.orgChild2Name +
" " +
orgRoot.orgRootCode +
orgChild2.orgChild2Code +
" " +
orgChild2.orgChild2ShortName +
"/" +
orgChild1.orgChild1Name +
" " +
orgRoot.orgRootCode +
orgChild1.orgChild1Code +
" " +
orgChild1.orgChild1ShortName +
"/" +
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
totalPosition: await this.posMasterRepository.count({ totalPosition: await this.posMasterRepository.count({
where: { where: {
orgRevisionId: orgRoot.orgRevisionId, orgRevisionId: orgRoot.orgRevisionId,
@ -5844,7 +5894,9 @@ export class OrganizationController extends Controller {
orgRoot.orgRootCode + orgRoot.orgRootCode +
orgChild1.orgChild1Code + orgChild1.orgChild1Code +
" " + " " +
orgChild1.orgChild1ShortName, orgChild1.orgChild1ShortName +
"/" +
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
posMaster: await Promise.all( posMaster: await Promise.all(
orgChild1.posMasters orgChild1.posMasters
.filter( .filter(
@ -5885,7 +5937,16 @@ export class OrganizationController extends Controller {
orgRoot.orgRootCode + orgRoot.orgRootCode +
orgChild2.orgChild2Code + orgChild2.orgChild2Code +
" " + " " +
orgChild2.orgChild2ShortName, orgChild2.orgChild2ShortName +
"/" +
orgChild1.orgChild1Name +
" " +
orgRoot.orgRootCode +
orgChild1.orgChild1Code +
" " +
orgChild1.orgChild1ShortName +
"/" +
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
posMaster: await Promise.all( posMaster: await Promise.all(
orgChild2.posMasters orgChild2.posMasters
.filter( .filter(
@ -5926,7 +5987,23 @@ export class OrganizationController extends Controller {
orgRoot.orgRootCode + orgRoot.orgRootCode +
orgChild3.orgChild3Code + orgChild3.orgChild3Code +
" " + " " +
orgChild3.orgChild3ShortName, orgChild3.orgChild3ShortName +
"/" +
orgChild2.orgChild2Name +
" " +
orgRoot.orgRootCode +
orgChild2.orgChild2Code +
" " +
orgChild2.orgChild2ShortName +
"/" +
orgChild1.orgChild1Name +
" " +
orgRoot.orgRootCode +
orgChild1.orgChild1Code +
" " +
orgChild1.orgChild1ShortName +
"/" +
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
posMaster: await Promise.all( posMaster: await Promise.all(
orgChild3.posMasters orgChild3.posMasters
.filter( .filter(
@ -5967,7 +6044,30 @@ export class OrganizationController extends Controller {
orgRoot.orgRootCode + orgRoot.orgRootCode +
orgChild4.orgChild4Code + orgChild4.orgChild4Code +
" " + " " +
orgChild4.orgChild4ShortName, orgChild4.orgChild4ShortName +
"/" +
orgChild3.orgChild3Name +
" " +
orgRoot.orgRootCode +
orgChild3.orgChild3Code +
" " +
orgChild3.orgChild3ShortName +
"/" +
orgChild2.orgChild2Name +
" " +
orgRoot.orgRootCode +
orgChild2.orgChild2Code +
" " +
orgChild2.orgChild2ShortName +
"/" +
orgChild1.orgChild1Name +
" " +
orgRoot.orgRootCode +
orgChild1.orgChild1Code +
" " +
orgChild1.orgChild1ShortName +
"/" +
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
posMaster: await Promise.all( posMaster: await Promise.all(
orgChild4.posMasters orgChild4.posMasters
.filter( .filter(
@ -6372,7 +6472,9 @@ export class OrganizationController extends Controller {
orgRoot.orgRootCode + orgRoot.orgRootCode +
orgChild1.orgChild1Code + orgChild1.orgChild1Code +
" " + " " +
orgChild1.orgChild1ShortName, orgChild1.orgChild1ShortName +
"/" +
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
totalPosition: await this.posMasterRepository.count({ totalPosition: await this.posMasterRepository.count({
where: { orgRevisionId: orgRoot.orgRevisionId, orgChild1Id: orgChild1.id }, where: { orgRevisionId: orgRoot.orgRevisionId, orgChild1Id: orgChild1.id },
}), }),
@ -6487,7 +6589,16 @@ export class OrganizationController extends Controller {
orgRoot.orgRootCode + orgRoot.orgRootCode +
orgChild2.orgChild2Code + orgChild2.orgChild2Code +
" " + " " +
orgChild2.orgChild2ShortName, orgChild2.orgChild2ShortName +
"/" +
orgChild1.orgChild1Name +
" " +
orgRoot.orgRootCode +
orgChild1.orgChild1Code +
" " +
orgChild1.orgChild1ShortName +
"/" +
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
totalPosition: await this.posMasterRepository.count({ totalPosition: await this.posMasterRepository.count({
where: { where: {
orgRevisionId: orgRoot.orgRevisionId, orgRevisionId: orgRoot.orgRevisionId,
@ -6605,7 +6716,23 @@ export class OrganizationController extends Controller {
orgRoot.orgRootCode + orgRoot.orgRootCode +
orgChild3.orgChild3Code + orgChild3.orgChild3Code +
" " + " " +
orgChild3.orgChild3ShortName, orgChild3.orgChild3ShortName +
"/" +
orgChild2.orgChild2Name +
" " +
orgRoot.orgRootCode +
orgChild2.orgChild2Code +
" " +
orgChild2.orgChild2ShortName +
"/" +
orgChild1.orgChild1Name +
" " +
orgRoot.orgRootCode +
orgChild1.orgChild1Code +
" " +
orgChild1.orgChild1ShortName +
"/" +
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
totalPosition: await this.posMasterRepository.count({ totalPosition: await this.posMasterRepository.count({
where: { where: {
orgRevisionId: orgRoot.orgRevisionId, orgRevisionId: orgRoot.orgRevisionId,
@ -6723,7 +6850,30 @@ export class OrganizationController extends Controller {
orgRoot.orgRootCode + orgRoot.orgRootCode +
orgChild4.orgChild4Code + orgChild4.orgChild4Code +
" " + " " +
orgChild4.orgChild4ShortName, orgChild4.orgChild4ShortName +
"/" +
orgChild3.orgChild3Name +
" " +
orgRoot.orgRootCode +
orgChild3.orgChild3Code +
" " +
orgChild3.orgChild3ShortName +
"/" +
orgChild2.orgChild2Name +
" " +
orgRoot.orgRootCode +
orgChild2.orgChild2Code +
" " +
orgChild2.orgChild2ShortName +
"/" +
orgChild1.orgChild1Name +
" " +
orgRoot.orgRootCode +
orgChild1.orgChild1Code +
" " +
orgChild1.orgChild1ShortName +
"/" +
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
totalPosition: await this.posMasterRepository.count({ totalPosition: await this.posMasterRepository.count({
where: { where: {
orgRevisionId: orgRoot.orgRevisionId, orgRevisionId: orgRoot.orgRevisionId,

View file

@ -451,6 +451,7 @@ export class OrganizationDotnetController extends Controller {
orgRevisionIsCurrent: true, orgRevisionIsCurrent: true,
orgRevisionIsDraft: false, orgRevisionIsDraft: false,
}, },
isDirector: true,
orgRootId: org?.root ?? "", orgRootId: org?.root ?? "",
orgChild1Id: IsNull(), orgChild1Id: IsNull(),
orgChild2Id: IsNull(), orgChild2Id: IsNull(),
@ -2619,6 +2620,280 @@ export class OrganizationDotnetController extends Controller {
return new HttpSuccess(profile_); return new HttpSuccess(profile_);
} }
/**
* 5. ,map keycloak id
*
* @summary 5. ,map keycloak id
*
*/
@Get("keycloak-employee")
async GetProfileWithKeycloakEmployee() {
const profile = await this.profileEmpRepo.find({
where: { keycloak: Not(IsNull()) || Not("") },
relations: [
"posType",
"posLevel",
"current_holders",
"current_holders.orgRoot",
"current_holders.orgChild1",
"current_holders.orgChild2",
"current_holders.orgChild3",
"current_holders.orgChild4",
"profileSalary",
],
order: {
profileSalary: {
order: "DESC",
},
},
});
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
const profile_ = await Promise.all(
profile.map((item: ProfileEmployee) => {
const rootName =
item.current_holders.length == 0
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot
?.orgRootName;
const shortName =
item.current_holders.length == 0
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 !=
null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
?.orgChild3 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
?.orgChild2 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
?.orgChild1 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) !=
null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
?.orgRoot != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: null;
return {
oc: rootName,
id: item.id,
createdAt: item.createdAt,
createdUserId: item.createdUserId,
lastUpdatedAt: item.lastUpdatedAt,
lastUpdateUserId: item.lastUpdateUserId,
createdFullName: item.createdFullName,
lastUpdateFullName: item.lastUpdateFullName,
avatar: item.avatar,
avatarName: item.avatarName,
rank: item.rank,
prefix: item.prefix,
firstName: item.firstName,
lastName: item.lastName,
citizenId: item.citizenId,
position: item.position,
posLevelId: item.posLevelId,
posTypeId: item.posTypeId,
email: item.email,
phone: item.phone,
keycloak: item.keycloak,
isProbation: item.isProbation,
isLeave: item.isLeave,
leaveReason: item.leaveReason,
dateLeave: item.dateLeave,
dateRetire: item.dateRetire,
dateAppoint: item.dateAppoint,
dateRetireLaw: item.dateRetireLaw,
dateStart: item.dateStart,
govAgeAbsent: item.govAgeAbsent,
govAgePlus: item.govAgePlus,
birthDate: item.birthDate ?? new Date(),
reasonSameDate: item.reasonSameDate,
ethnicity: item.ethnicity,
telephoneNumber: item.telephoneNumber,
nationality: item.nationality,
gender: item.gender,
relationship: item.relationship,
religion: item.religion,
bloodGroup: item.bloodGroup,
registrationAddress: item.registrationAddress,
registrationProvinceId: item.registrationProvinceId,
registrationDistrictId: item.registrationDistrictId,
registrationSubDistrictId: item.registrationSubDistrictId,
registrationZipCode: item.registrationZipCode,
currentAddress: item.currentAddress,
currentProvinceId: item.currentProvinceId,
currentDistrictId: item.currentDistrictId,
currentSubDistrictId: item.currentSubDistrictId,
currentZipCode: item.currentZipCode,
dutyTimeId: item.dutyTimeId,
dutyTimeEffectiveDate: item.dutyTimeEffectiveDate,
positionLevel: item.profileSalary.length > 0 ? item.profileSalary[0].positionLevel : null,
posNo: shortName,
};
}),
);
return new HttpSuccess(profile_);
}
/**
* 5. ,map keycloak id
*
* @summary 5. ,map keycloak id
*
*/
@Post("keycloak-all-officer")
async PostProfileWithKeycloakAllOfficer(
@Request() req: RequestWithUser,
@Body()
body: {
node: string;
nodeId: string;
},
) {
const profile = await this.profileRepo.find({
where: { keycloak: Not(IsNull()) || Not(""), isLeave: false },
relations: [
"current_holders",
"current_holders.orgRoot",
"current_holders.orgChild1",
"current_holders.orgChild2",
"current_holders.orgChild3",
"current_holders.orgChild4",
],
});
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
const profile_ = await Promise.all(
profile.map((item: Profile) => {
const shortName =
item.current_holders.length == 0
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 !=
null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
?.orgChild3 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
?.orgChild2 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
?.orgChild1 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) !=
null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
?.orgRoot != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: null;
return {
id: item.id,
prefix: item.prefix,
firstName: item.firstName,
lastName: item.lastName,
keycloak: item.keycloak,
posNo: shortName,
};
}),
);
return new HttpSuccess(profile_);
}
/**
* 5. ,map keycloak id
*
* @summary 5. ,map keycloak id
*
*/
@Post("keycloak-all-employee")
async PostProfileWithKeycloakAllEmployee(
@Request() req: RequestWithUser,
@Body()
body: {
node: string;
nodeId: string;
},
) {
const profile = await this.profileEmpRepo.find({
where: { keycloak: Not(IsNull()) || Not(""), isLeave: false },
relations: [
"current_holders",
"current_holders.orgRoot",
"current_holders.orgChild1",
"current_holders.orgChild2",
"current_holders.orgChild3",
"current_holders.orgChild4",
],
});
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
const profile_ = await Promise.all(
profile.map((item: ProfileEmployee) => {
const shortName =
item.current_holders.length == 0
? null
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 !=
null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
?.orgChild3 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
?.orgChild2 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
?.orgChild1 != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) !=
null &&
item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
?.orgRoot != null
? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
: null;
return {
id: item.id,
prefix: item.prefix,
firstName: item.firstName,
lastName: item.lastName,
citizenId: item.citizenId,
keycloak: item.keycloak,
posNo: shortName,
};
}),
);
return new HttpSuccess(profile_);
}
/** /**
* 4. API Update profile * 4. API Update profile
* *

View file

@ -4953,6 +4953,7 @@ export class PositionController extends Controller {
(masterId.length > 0 (masterId.length > 0
? { id: In(masterId) } ? { id: In(masterId) }
: { posMasterNo: Like(`%${body.keyword}%`) })), : { posMasterNo: Like(`%${body.keyword}%`) })),
current_holderId: IsNull(),
}, },
]; ];
let [posMaster, total] = await AppDataSource.getRepository(PosMaster) let [posMaster, total] = await AppDataSource.getRepository(PosMaster)
@ -4962,10 +4963,11 @@ export class PositionController extends Controller {
.leftJoinAndSelect("posMaster.orgChild2", "orgChild2") .leftJoinAndSelect("posMaster.orgChild2", "orgChild2")
.leftJoinAndSelect("posMaster.orgChild3", "orgChild3") .leftJoinAndSelect("posMaster.orgChild3", "orgChild3")
.leftJoinAndSelect("posMaster.orgChild4", "orgChild4") .leftJoinAndSelect("posMaster.orgChild4", "orgChild4")
.leftJoinAndSelect("posMaster.orgRevision", "orgRevision")
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
.leftJoinAndSelect("current_holder.posType", "posType")
.leftJoinAndSelect("current_holder.posLevel", "posLevel")
.where(conditions) .where(conditions)
.andWhere({
current_holderId: IsNull(),
})
.andWhere( .andWhere(
_data.root != undefined && _data.root != null _data.root != undefined && _data.root != null
? _data.root[0] != null ? _data.root[0] != null
@ -5016,13 +5018,21 @@ export class PositionController extends Controller {
child4: _data.child4, child4: _data.child4,
}, },
) )
.andWhere( .orWhere(
new Brackets((qb) => {
qb.andWhere(
body.keyword != null && body.keyword != "" body.keyword != null && body.keyword != ""
? body.isAll == false ? body.isAll == false
? searchShortName ? searchShortName
: `CASE WHEN posMaster.orgChild1 is null THEN ${searchShortName0} WHEN posMaster.orgChild2 is null THEN ${searchShortName1} WHEN posMaster.orgChild3 is null THEN ${searchShortName2} WHEN posMaster.orgChild4 is null THEN ${searchShortName3} ELSE ${searchShortName4} END LIKE '%${body.keyword}%'` : `CASE WHEN posMaster.orgChild1 is null THEN ${searchShortName0} WHEN posMaster.orgChild2 is null THEN ${searchShortName1} WHEN posMaster.orgChild3 is null THEN ${searchShortName2} WHEN posMaster.orgChild4 is null THEN ${searchShortName3} ELSE ${searchShortName4} END LIKE '%${body.keyword}%'`
: "1=1", : "1=1",
) )
.andWhere(checkChildConditions)
.andWhere(typeCondition)
.andWhere(revisionCondition)
.andWhere({ current_holderId: IsNull() });
}),
)
.orderBy("posMaster.posMasterOrder", "ASC") .orderBy("posMaster.posMasterOrder", "ASC")
.skip((body.page - 1) * body.pageSize) .skip((body.page - 1) * body.pageSize)
.take(body.pageSize) .take(body.pageSize)

View file

@ -278,7 +278,7 @@ export class ProfileController extends Controller {
: "-", : "-",
ocFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`, ocFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
educations: Education, educations: Education,
url: ImgUrl ? ImgUrl : `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`, url: ImgUrl ? ImgUrl : `${process.env.VITE_URL_SSO}/assets/avatar_user-89f22423.jpg`,
}; };
return new HttpSuccess({ return new HttpSuccess({
@ -715,7 +715,7 @@ export class ProfileController extends Controller {
: "", : "",
telephone: telephone:
profiles.telephoneNumber != null ? Extension.ToThaiNumber(profiles.telephoneNumber) : "", profiles.telephoneNumber != null ? Extension.ToThaiNumber(profiles.telephoneNumber) : "",
url: ImgUrl ? ImgUrl : `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`, url: ImgUrl ? ImgUrl : `${process.env.VITE_URL_SSO}/assets/avatar_user-89f22423.jpg`,
url1: _ImgUrl[0] ? _ImgUrl[0] : null, url1: _ImgUrl[0] ? _ImgUrl[0] : null,
yearUpload1: profiles.profileAvatars[0] yearUpload1: profiles.profileAvatars[0]
? Extension.ToThaiNumber(Extension.ToThaiShortYear(profiles.profileAvatars[0].createdAt)) ? Extension.ToThaiNumber(Extension.ToThaiShortYear(profiles.profileAvatars[0].createdAt))
@ -4248,8 +4248,8 @@ export class ProfileController extends Controller {
{ {
keyword: `%${searchKeyword}%`, keyword: `%${searchKeyword}%`,
}, },
) );
}) }),
) )
.orderBy("current_holders.posMasterNo", "ASC") .orderBy("current_holders.posMasterNo", "ASC")
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
@ -6030,8 +6030,8 @@ export class ProfileController extends Controller {
where: { where: {
citizenId: Like(`%${body.keyword}%`), citizenId: Like(`%${body.keyword}%`),
current_holders: { current_holders: {
orgRevisionId:revision?.id orgRevisionId: revision?.id,
} },
}, },
relations: [ relations: [
"posType", "posType",
@ -6050,7 +6050,8 @@ export class ProfileController extends Controller {
break; break;
case "fullName": case "fullName":
[findProfile, total] = await this.profileRepo.createQueryBuilder("profile") [findProfile, total] = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.posType", "posType") .leftJoinAndSelect("profile.posType", "posType")
.leftJoinAndSelect("profile.posLevel", "posLevel") .leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.current_holders", "current_holders") .leftJoinAndSelect("profile.current_holders", "current_holders")
@ -6060,7 +6061,10 @@ export class ProfileController extends Controller {
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3") .leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4") .leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.where("current_holders.orgRevision = :revisionId", { revisionId: revision?.id }) .where("current_holders.orgRevision = :revisionId", { revisionId: revision?.id })
.andWhere("CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword", { keyword: `%${body.keyword}%` }) .andWhere(
"CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword",
{ keyword: `%${body.keyword}%` },
)
.skip(skip) .skip(skip)
.take(take) .take(take)
.getManyAndCount(); .getManyAndCount();
@ -6071,8 +6075,8 @@ export class ProfileController extends Controller {
where: { where: {
position: Like(`%${body.keyword}%`), position: Like(`%${body.keyword}%`),
current_holders: { current_holders: {
orgRevisionId:revision?.id orgRevisionId: revision?.id,
} },
}, },
relations: [ relations: [
"posType", "posType",
@ -6091,7 +6095,8 @@ export class ProfileController extends Controller {
break; break;
case "posNo": case "posNo":
[findProfile, total] = await this.profileRepo.createQueryBuilder("profile") [findProfile, total] = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.posType", "posType") .leftJoinAndSelect("profile.posType", "posType")
.leftJoinAndSelect("profile.posLevel", "posLevel") .leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.current_holders", "current_holders") .leftJoinAndSelect("profile.current_holders", "current_holders")
@ -6103,13 +6108,15 @@ export class ProfileController extends Controller {
.where("current_holders.orgRevision = :revisionId", { revisionId: revision?.id }) .where("current_holders.orgRevision = :revisionId", { revisionId: revision?.id })
.andWhere( .andWhere(
new Brackets((qb) => { new Brackets((qb) => {
qb.orWhere(body.keyword != undefined && body.keyword != null && body.keyword != "" qb.orWhere(
body.keyword != undefined && body.keyword != null && body.keyword != ""
? queryLike ? queryLike
: "1=1", : "1=1",
{ {
keyword: `%${body.keyword}%`, keyword: `%${body.keyword}%`,
}) },
}) );
}),
) )
.skip(skip) .skip(skip)
.take(take) .take(take)
@ -6120,11 +6127,11 @@ export class ProfileController extends Controller {
[findProfile, total] = await this.profileRepo.findAndCount({ [findProfile, total] = await this.profileRepo.findAndCount({
where: { where: {
posType: { posType: {
posTypeName:Like(`%${body.keyword}%`) posTypeName: Like(`%${body.keyword}%`),
}, },
current_holders: { current_holders: {
orgRevisionId:revision?.id orgRevisionId: revision?.id,
} },
}, },
relations: [ relations: [
"posType", "posType",
@ -6146,11 +6153,11 @@ export class ProfileController extends Controller {
[findProfile, total] = await this.profileRepo.findAndCount({ [findProfile, total] = await this.profileRepo.findAndCount({
where: { where: {
posLevel: { posLevel: {
posLevelName:Like(`%${body.keyword}%`) posLevelName: Like(`%${body.keyword}%`),
}, },
current_holders: { current_holders: {
orgRevisionId:revision?.id orgRevisionId: revision?.id,
} },
}, },
relations: [ relations: [
"posType", "posType",
@ -6174,9 +6181,10 @@ export class ProfileController extends Controller {
current_holders: { current_holders: {
orgRevisionId: revision?.id, orgRevisionId: revision?.id,
orgRoot: { orgRoot: {
orgRootName:Like(`%${body.keyword}%`) orgRootName: Like(`%${body.keyword}%`),
} },
}}, },
},
relations: [ relations: [
"posType", "posType",
"posLevel", "posLevel",
@ -6197,8 +6205,8 @@ export class ProfileController extends Controller {
[findProfile, total] = await this.profileRepo.findAndCount({ [findProfile, total] = await this.profileRepo.findAndCount({
where: { where: {
current_holders: { current_holders: {
orgRevisionId:revision?.id orgRevisionId: revision?.id,
} },
}, },
relations: [ relations: [
"posType", "posType",

View file

@ -284,7 +284,7 @@ export class ProfileEmployeeController extends Controller {
: "-", : "-",
ocFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`, ocFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
educations: Education, educations: Education,
url: ImgUrl ? ImgUrl : `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`, url: ImgUrl ? ImgUrl : `${process.env.VITE_URL_SSO}/assets/avatar_user-89f22423.jpg`,
}; };
return new HttpSuccess({ return new HttpSuccess({
@ -722,7 +722,7 @@ export class ProfileEmployeeController extends Controller {
: "", : "",
telephone: telephone:
profiles.telephoneNumber != null ? Extension.ToThaiNumber(profiles.telephoneNumber) : "", profiles.telephoneNumber != null ? Extension.ToThaiNumber(profiles.telephoneNumber) : "",
url: ImgUrl ? ImgUrl : `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`, url: ImgUrl ? ImgUrl : `${process.env.VITE_URL_SSO}/assets/avatar_user-89f22423.jpg`,
url1: _ImgUrl[0] ? _ImgUrl[0] : null, url1: _ImgUrl[0] ? _ImgUrl[0] : null,
yearUpload1: profiles.profileAvatars[0] yearUpload1: profiles.profileAvatars[0]
? Extension.ToThaiNumber(Extension.ToThaiShortYear(profiles.profileAvatars[0].createdAt)) ? Extension.ToThaiNumber(Extension.ToThaiShortYear(profiles.profileAvatars[0].createdAt))

View file

@ -281,7 +281,7 @@ export class ProfileEmployeeTempController extends Controller {
: "-", : "-",
ocFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`, ocFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
educations: Education, educations: Education,
url: ImgUrl ? ImgUrl : `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`, url: ImgUrl ? ImgUrl : `${process.env.VITE_URL_SSO}/assets/avatar_user-89f22423.jpg`,
}; };
return new HttpSuccess({ return new HttpSuccess({
@ -719,7 +719,7 @@ export class ProfileEmployeeTempController extends Controller {
: "", : "",
telephone: telephone:
profiles.telephoneNumber != null ? Extension.ToThaiNumber(profiles.telephoneNumber) : "", profiles.telephoneNumber != null ? Extension.ToThaiNumber(profiles.telephoneNumber) : "",
url: ImgUrl ? ImgUrl : `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`, url: ImgUrl ? ImgUrl : `${process.env.VITE_URL_SSO}/assets/avatar_user-89f22423.jpg`,
url1: _ImgUrl[0] ? _ImgUrl[0] : null, url1: _ImgUrl[0] ? _ImgUrl[0] : null,
yearUpload1: profiles.profileAvatars[0] yearUpload1: profiles.profileAvatars[0]
? Extension.ToThaiNumber(Extension.ToThaiShortYear(profiles.profileAvatars[0].createdAt)) ? Extension.ToThaiNumber(Extension.ToThaiShortYear(profiles.profileAvatars[0].createdAt))

View file

@ -628,7 +628,7 @@ export class WorkflowController extends Controller {
if (!state) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลขั้นตอนการอนุมัติ"); if (!state) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลขั้นตอนการอนุมัติ");
if (state.stateUserComments.filter((x) => x.profileId == body.profileId).length > 0) if (state.stateUserComments.filter((x) => x.profileId == body.profileId).length > 0)
throw new HttpError(HttpStatus.NOT_FOUND, "มีผู้ใช้งานนี้อยู่แล้ว"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่สามารถเลือกซ้ำได้");
const stateUserComment = new StateUserComment(); const stateUserComment = new StateUserComment();
stateUserComment.order = state.stateUserComments.length + 1; stateUserComment.order = state.stateUserComments.length + 1;

View file

@ -92,7 +92,7 @@ export async function calculateGovAge(profileId: string, type: string) {
} }
}) })
// const firstStartDate = new Date(records[0].date); // const firstStartDate = new Date(records[0].date);
const firstStartDate = profile?.dateAppoint; const firstStartDate = profile?.dateAppoint ? profile?.dateAppoint : new Date();
const firstEndDate = endDateFristRec ? new Date(endDateFristRec.dateGovernment) : new Date(); const firstEndDate = endDateFristRec ? new Date(endDateFristRec.dateGovernment) : new Date();
const { const {