diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 0c2f7ac7..14f4692b 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -2529,8 +2529,8 @@ export class PositionController extends Controller { nodeId: string; position: string; typeCommand: string | null; - posType: string; - posLevel: string; + posType?: string | null; + posLevel?: string | null; isAll: boolean; isBlank: boolean; }, @@ -2545,13 +2545,15 @@ export class PositionController extends Controller { where: { id: String(body.posLevel) }, }); - if (body.typeCommand == "APPOINTED" || body.typeCommand == "MOVE") { - conditionA = "positions.posTypeId LIKE :posType AND positions.posLevelId LIKE :posLevel"; - } else if (body.typeCommand == "APPOINT") { - conditionA = "posType.posTypeRank > :posTypeRank"; - } else if (body.typeCommand == "SLIP") { - conditionA = "positions.posTypeId LIKE :posType AND posLevel.posLevelRank > :posLevelRank"; - } + if (body.typeCommand == "APPOINTED" || body.typeCommand == "MOVE") { + conditionA = + "positions.posTypeId LIKE :posType AND positions.posLevelId LIKE :posLevel"; + } else if (body.typeCommand == "APPOINT") { + conditionA = "posType.posTypeRank > :posTypeRank"; + } else if (body.typeCommand == "SLIP") { + conditionA = + "positions.posTypeId LIKE :posType AND posLevel.posLevelRank > :posLevelRank"; + } if (body.isAll == false) { if (body.node === 0) { @@ -2629,10 +2631,10 @@ export class PositionController extends Controller { .andWhere( new Brackets((qb) => { qb.andWhere(typeCondition).andWhere(conditionA == null ? "1=1" : conditionA, { - posType: `${body.posType}`, - posLevel: `${body.posLevel}`, - posTypeRank: posType == null ? 0 : posType.posTypeRank, - posLevelRank: posLevel == null ? 0 : posLevel.posLevelRank, + posType: posType == null ? `%%` : `%${posType.id}%`, + posLevel: posLevel == null ? `%%` : `%${posLevel.id}%`, + posTypeRank: posType == null ? "" : posType.posTypeRank, + posLevelRank: posLevel == null ? "" : posLevel.posLevelRank, }); }), ) @@ -2754,8 +2756,8 @@ export class PositionController extends Controller { nodeId: string; position: string; typeCommand: string | null; - posType: string; - posLevel: string; + posType?: string | null; + posLevel?: string | null; isAll: boolean; isBlank: boolean; }, @@ -2854,10 +2856,10 @@ export class PositionController extends Controller { .andWhere( new Brackets((qb) => { qb.andWhere(typeCondition).andWhere(conditionA == null ? "1=1" : conditionA, { - posType: `${body.posType}`, - posLevel: `${body.posLevel}`, - posTypeRank: posType == null ? 0 : posType.posTypeRank, - posLevelRank: posLevel == null ? 0 : posLevel.posLevelRank, + posType: posType == null ? `%%` : `%${posType.id}%`, + posLevel: posLevel == null ? `%%` : `%${posLevel.id}%`, + posTypeRank: posType == null ? "" : posType.posTypeRank, + posLevelRank: posLevel == null ? "" : posLevel.posLevelRank, }); }), ) diff --git a/src/controllers/ProfileAbilityController.ts b/src/controllers/ProfileAbilityController.ts index facb4d29..9f795bd9 100644 --- a/src/controllers/ProfileAbilityController.ts +++ b/src/controllers/ProfileAbilityController.ts @@ -79,6 +79,25 @@ export class ProfileAbilityController extends Controller { return new HttpSuccess(getProfileAbilityId); } + @Get("history/user") + public async getProfileAbilityHistoryUser(@Request() request: RequestWithUser) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.profileAbilityHistoryRepo.find({ + where: { + histories: { + profileId: profile.id, + }, + }, + }); + if (!record) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + return new HttpSuccess(record); + } + @Get("history/{abilityId}") @Example({ status: 200, diff --git a/src/controllers/ProfileAbilityEmployeeController.ts b/src/controllers/ProfileAbilityEmployeeController.ts index 47c56d92..e3303a3d 100644 --- a/src/controllers/ProfileAbilityEmployeeController.ts +++ b/src/controllers/ProfileAbilityEmployeeController.ts @@ -81,6 +81,25 @@ export class ProfileAbilityEmployeeController extends Controller { return new HttpSuccess(getProfileAbilityId); } + @Get("history/user") + public async getProfileAbilityHistoryUser(@Request() request: RequestWithUser) { + const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.profileAbilityHistoryRepo.find({ + where: { + histories: { + profileEmployeeId: profile.id, + }, + }, + }); + if (!record) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + return new HttpSuccess(record); + } + @Get("history/{abilityId}") @Example({ status: 200, diff --git a/src/controllers/ProfileAddressController.ts b/src/controllers/ProfileAddressController.ts index 497d45b7..156a6160 100644 --- a/src/controllers/ProfileAddressController.ts +++ b/src/controllers/ProfileAddressController.ts @@ -91,6 +91,48 @@ export class ProfileAddressController extends Controller { return new HttpSuccess(getProfileAddress); } + /** + * + * @summary ประวัติแก้ไขที่อยู่ by keycloak + * + */ + @Get("history/user") + public async getProfileAddressHistoryUser(@Request() request: RequestWithUser) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.profileAddressHistoryRepo.find({ + where: { profileId: profile.id }, + relations: { + registrationProvince: true, + registrationDistrict: true, + registrationSubDistrict: true, + currentProvince: true, + currentDistrict: true, + currentSubDistrict: true, + }, + select: [ + "registrationAddress", + "registrationProvinceId", + "registrationDistrictId", + "registrationSubDistrictId", + "registrationZipCode", + "currentAddress", + "currentProvinceId", + "currentDistrictId", + "currentSubDistrictId", + "currentZipCode", + "lastUpdateFullName", + "lastUpdatedAt", + ], + }); + if (!record) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + return new HttpSuccess(record); + } + /** * * @summary ประวัติแก้ไขที่อยู่ diff --git a/src/controllers/ProfileAddressEmployeeController.ts b/src/controllers/ProfileAddressEmployeeController.ts index b6f4aced..3ec8a3d9 100644 --- a/src/controllers/ProfileAddressEmployeeController.ts +++ b/src/controllers/ProfileAddressEmployeeController.ts @@ -92,6 +92,48 @@ export class ProfileAddressEmployeeController extends Controller { return new HttpSuccess(getProfileAddress); } + /** + * + * @summary ประวัติแก้ไขที่อยู่ by keycloak + * + */ + @Get("history/user") + public async getProfileAddressHistoryUser(@Request() request: RequestWithUser) { + const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.profileAddressHistoryRepo.find({ + where: { profileEmployeeId: profile.id}, + relations: { + registrationProvince: true, + registrationDistrict: true, + registrationSubDistrict: true, + currentProvince: true, + currentDistrict: true, + currentSubDistrict: true, + }, + select: [ + "registrationAddress", + "registrationProvinceId", + "registrationDistrictId", + "registrationSubDistrictId", + "registrationZipCode", + "currentAddress", + "currentProvinceId", + "currentDistrictId", + "currentSubDistrictId", + "currentZipCode", + "lastUpdateFullName", + "lastUpdatedAt", + ], + }); + if (!record) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + return new HttpSuccess(record); + } + /** * * @summary ประวัติแก้ไขที่อยู่