diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index 5d0fb211..88052384 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -106,7 +106,15 @@ export class OrganizationDotnetController extends Controller { const queryBuilder = profileRepository .createQueryBuilder("profile") .leftJoinAndSelect("profile.posLevel", "posLevel") - .leftJoinAndSelect("profile.posType", "posType"); + .leftJoinAndSelect("profile.posType", "posType") + .leftJoinAndSelect("profile.profileSalarys", "profileSalarys") + .leftJoinAndSelect("profile.current_holders", "current_holders") + .leftJoinAndSelect("current_holders.orgRoot", "orgRoot") + .leftJoinAndSelect("current_holders.orgChild1", "orgChild1") + .leftJoinAndSelect("current_holders.orgChild2", "orgChild2") + .leftJoinAndSelect("current_holders.orgChild3", "orgChild3") + .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") + .orderBy("profileSalarys.order", "DESC"); if (body.citizenId || body.firstName || body.lastName) { queryBuilder.where( @@ -123,8 +131,102 @@ export class OrganizationDotnetController extends Controller { }), ); } + const profileEmp = await queryBuilder.getMany(); - return new HttpSuccess(profileEmp); + + const findRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: true }, + }); + + const profileEmp_ = await Promise.all( + profileEmp.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, + 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, + posLevel: item.posLevel, + posType: item.posType, + posNo: shortName + } + }) + ); + return new HttpSuccess(profileEmp_); } /** @@ -799,8 +901,122 @@ export class OrganizationDotnetController extends Controller { async GetProfileWithKeycloak() { const profile = await this.profileRepo.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", + }, + }, }); - return new HttpSuccess(profile); + + const findRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: true }, + }); + + const profile_ = await Promise.all( + profile.map((item: Profile) => { + 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, + 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_); } /** diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 08142f0d..e8a1feb7 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -2563,6 +2563,9 @@ export class ProfileController extends Controller { posType: true, }, where: { profileId: id }, + order: { + createdAt: "ASC", + }, }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 9069ccc9..4e8d0ca0 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -665,17 +665,6 @@ export class ProfileEmployeeController extends Controller { const record = await this.profileRepo.findOneBy({ id }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้"); - await this.profileHistoryRepo.save( - Object.assign(new ProfileEmployeeHistory(), { - ...record, - lastUpdateUserId: request.user.sub, - lastUpdateFullName: request.user.name, - lastUpdatedAt: new Date(), - profileEmployeeId: id, - id: undefined, - }), - ); - if (body.employeeClass == null || body.employeeClass == undefined || body.employeeClass == "") { body.employeeClass = "PERM"; } @@ -691,6 +680,16 @@ export class ProfileEmployeeController extends Controller { record.dateRetireLaw = calculateRetireLaw(record.birthDate); record.citizenId = Extension.CheckCitizen(record.citizenId); record.employeeClass = record.employeeClass.toLocaleUpperCase(); + await this.profileHistoryRepo.save( + Object.assign(new ProfileEmployeeHistory(), { + ...record, + lastUpdateUserId: request.user.sub, + lastUpdateFullName: request.user.name, + lastUpdatedAt: new Date(), + profileEmployeeId: id, + id: undefined, + }), + ); await this.profileRepo.save(record); return new HttpSuccess(); } @@ -1395,11 +1394,11 @@ export class ProfileEmployeeController extends Controller { relations: { posLevel: true, posType: true, - // gender: true, - // relationship: true, - // bloodGroup: true, }, where: { profileEmployeeId: id }, + order: { + createdAt: "ASC", + }, }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -3037,36 +3036,13 @@ export class ProfileEmployeeController extends Controller { @Get("information/history/{profileEmployeeId}") async getInformationHistory(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) { await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId); - const profileInformation = await this.profileRepo.find({ - relations: { - information_histories: true, + const profileInformation = await this.informationHistoryRepository.find({ + where: { profileEmployeeId: profileEmployeeId }, + order: { + createdAt: "ASC", }, - where: { id: profileEmployeeId }, }); - if (!profileInformation) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - - const mapData = profileInformation - .flatMap((profile) => profile.information_histories) - .map((history) => ({ - id: history.id, - positionEmployeeGroupId: history.positionEmployeeGroupId, - positionEmployeeLineId: history.positionEmployeeLineId, - positionEmployeePositionId: history.positionEmployeePositionId, - employeeOc: history.employeeOc, - employeeTypeIndividual: history.employeeTypeIndividual, - employeeWage: history.employeeWage, - employeeMoneyIncrease: history.employeeMoneyIncrease, - employeeMoneyAllowance: history.employeeMoneyAllowance, - employeeMoneyEmployee: history.employeeMoneyEmployee, - employeeMoneyEmployer: history.employeeMoneyEmployer, - createdAt: history.createdAt, - createdUserId: history.createdUserId, - createdFullName: history.createdFullName, - lastUpdatedAt: history.lastUpdatedAt, - lastUpdateUserId: history.lastUpdateUserId, - lastUpdateFullName: history.lastUpdateFullName, - })); - return new HttpSuccess(mapData); + return new HttpSuccess(profileInformation); } /** diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index 6dcfc92f..8d298273 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -662,14 +662,6 @@ export class ProfileEmployeeTempController extends Controller { const record = await this.profileRepo.findOneBy({ id }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้"); - await this.profileHistoryRepo.save( - Object.assign(new ProfileEmployeeHistory(), { - ...record, - profileEmployeeId: id, - id: undefined, - }), - ); - if (body.employeeClass == null || body.employeeClass == undefined || body.employeeClass == "") { body.employeeClass = "PERM"; } @@ -685,6 +677,13 @@ export class ProfileEmployeeTempController extends Controller { record.dateRetireLaw = calculateRetireLaw(record.birthDate); record.citizenId = Extension.CheckCitizen(record.citizenId); record.employeeClass = record.employeeClass.toLocaleUpperCase(); + await this.profileHistoryRepo.save( + Object.assign(new ProfileEmployeeHistory(), { + ...record, + profileEmployeeId: id, + id: undefined, + }), + ); await this.profileRepo.save(record); return new HttpSuccess(); } @@ -1333,11 +1332,11 @@ export class ProfileEmployeeTempController extends Controller { relations: { posLevel: true, posType: true, - // gender: true, - // relationship: true, - // bloodGroup: true, }, where: { profileEmployeeId: id }, + order: { + createdAt: "ASC", + }, }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -2973,36 +2972,13 @@ export class ProfileEmployeeTempController extends Controller { @Get("information/history/{profileEmployeeId}") async getInformationHistory(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) { await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP"); - const profileInformation = await this.profileRepo.find({ - relations: { - information_histories: true, + const profileInformation = await this.informationHistoryRepository.find({ + where: { profileEmployeeId: profileEmployeeId }, + order: { + createdAt: "ASC", }, - where: { id: profileEmployeeId }, }); - if (!profileInformation) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - - const mapData = profileInformation - .flatMap((profile) => profile.information_histories) - .map((history) => ({ - id: history.id, - positionEmployeeGroupId: history.positionEmployeeGroupId, - positionEmployeeLineId: history.positionEmployeeLineId, - positionEmployeePositionId: history.positionEmployeePositionId, - employeeOc: history.employeeOc, - employeeTypeIndividual: history.employeeTypeIndividual, - employeeWage: history.employeeWage, - employeeMoneyIncrease: history.employeeMoneyIncrease, - employeeMoneyAllowance: history.employeeMoneyAllowance, - employeeMoneyEmployee: history.employeeMoneyEmployee, - employeeMoneyEmployer: history.employeeMoneyEmployer, - createdAt: history.createdAt, - createdUserId: history.createdUserId, - createdFullName: history.createdFullName, - lastUpdatedAt: history.lastUpdatedAt, - lastUpdateUserId: history.lastUpdateUserId, - lastUpdateFullName: history.lastUpdateFullName, - })); - return new HttpSuccess(mapData); + return new HttpSuccess(profileInformation); } /** diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 8c204e64..fbd4d7b0 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -689,7 +689,6 @@ export class ReportController extends Controller { } } } - console.log(data); return new HttpSuccess({ template: "report1", reportName: "report1", data: { data } }); } diff --git a/src/database/data-source.ts b/src/database/data-source.ts index 4138f1ce..efc31da6 100644 --- a/src/database/data-source.ts +++ b/src/database/data-source.ts @@ -22,6 +22,5 @@ export const AppDataSource = new DataSource({ : ["dist/migration/**/*{.ts,.js}"], subscribers: [], }); -// console.log(AppDataSource); // export default database; diff --git a/src/interfaces/extension.ts b/src/interfaces/extension.ts index e6c256de..6d11543c 100644 --- a/src/interfaces/extension.ts +++ b/src/interfaces/extension.ts @@ -357,7 +357,6 @@ class Extension { }); const delAsync = promisify(redisClient.del).bind(redisClient); const deleteKey = delAsync(type + id); - console.log(`Deleted ${deleteKey} keys.`); return; } } diff --git a/src/keycloak/index.ts b/src/keycloak/index.ts index ab6f765d..205c83cd 100644 --- a/src/keycloak/index.ts +++ b/src/keycloak/index.ts @@ -5,8 +5,6 @@ const KC_REALM = process.env.KC_REALM; const KC_CLIENT_ID = process.env.KC_SERVICE_ACCOUNT_CLIENT_ID; const KC_SECRET = process.env.KC_SERVICE_ACCOUNT_SECRET; -console.log(process.env.KC_URL); - let token: string | null = null; let decoded: DecodedJwt | null = null;