diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 636a4e48..bc02a392 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -9781,6 +9781,8 @@ export class ProfileController extends Controller { rootId?: string; year: number; period: string; + sortBy?: string; + descending?: boolean; }, ) { const findRevision = await this.orgRevisionRepo.findOne({ @@ -9790,7 +9792,7 @@ export class ProfileController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); } - const [findPosMaster, total] = await AppDataSource.getRepository(PosMaster) + let query = await AppDataSource.getRepository(PosMaster) .createQueryBuilder("posMaster") .leftJoinAndSelect("posMaster.current_holder", "current_holder") .leftJoinAndSelect("posMaster.orgRoot", "orgRoot") @@ -9923,7 +9925,37 @@ export class ProfileController extends Controller { ); }), ) - .orderBy("current_holder.citizenId", "ASC") + + if (body.sortBy) { + if(body.sortBy === "posType"){ + query = query.orderBy( + `posType.posTypeName`, + body.descending ? "DESC" : "ASC" + ); + }else if(body.sortBy === "posLevel"){ + query = query.orderBy( + `posLevel.posLevelName`, + body.descending ? "DESC" : "ASC" + ); + }else if(body.sortBy === "orgShortName" || body.sortBy === "posMasterNo"){ + query = query + .orderBy(`orgRoot.orgRootShortName`,body.descending ? "DESC" : "ASC") + .addOrderBy(`orgChild1.orgChild1ShortName`,body.descending ? "DESC" : "ASC") + .addOrderBy(`orgChild2.orgChild2ShortName`,body.descending ? "DESC" : "ASC") + .addOrderBy(`orgChild3.orgChild3ShortName`,body.descending ? "DESC" : "ASC") + .addOrderBy(`orgChild4.orgChild4ShortName`,body.descending ? "DESC" : "ASC") + .addOrderBy(`posMaster.posMasterNo`,body.descending ? "DESC" : "ASC") + }else{ + query = query.orderBy( + `current_holder.${body.sortBy}`, + body.descending ? "DESC" : "ASC" + ); + } + }else{ + query = query.orderBy("current_holder.citizenId", "ASC") + } + + const [findPosMaster, total] = await query .skip((body.page - 1) * body.pageSize) .take(body.pageSize) .getManyAndCount(); diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 4bc85898..076881de 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -4981,6 +4981,8 @@ export class ProfileEmployeeController extends Controller { rootId?: string; year: number; period: string; + sortBy?: string; + descending?: boolean; }, ) { const findRevision = await this.orgRevisionRepo.findOne({ @@ -4990,7 +4992,7 @@ export class ProfileEmployeeController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); } - const [findPosMaster, total] = await AppDataSource.getRepository(EmployeePosMaster) + let query = await AppDataSource.getRepository(EmployeePosMaster) .createQueryBuilder("employeePosMaster") .leftJoinAndSelect("employeePosMaster.current_holder", "current_holder") .leftJoinAndSelect("employeePosMaster.orgRoot", "orgRoot") @@ -5122,10 +5124,40 @@ export class ProfileEmployeeController extends Controller { ); }), ) - .orderBy("current_holder.citizenId", "ASC") + + if (body.sortBy) { + if(body.sortBy === "posType"){ + query = query.orderBy( + `posType.posTypeName`, + body.descending ? "DESC" : "ASC" + ); + }else if(body.sortBy === "posLevel"){ + query = query + .orderBy(`posType.posTypeShortName`,body.descending ? "DESC" : "ASC") + .addOrderBy(`posLevel.posLevelName`,body.descending ? "DESC" : "ASC"); + }else if(body.sortBy === "orgShortName" || body.sortBy === "posMasterNo"){ + query = query + .orderBy(`orgRoot.orgRootShortName`,body.descending ? "DESC" : "ASC") + .addOrderBy(`orgChild1.orgChild1ShortName`,body.descending ? "DESC" : "ASC") + .addOrderBy(`orgChild2.orgChild2ShortName`,body.descending ? "DESC" : "ASC") + .addOrderBy(`orgChild3.orgChild3ShortName`,body.descending ? "DESC" : "ASC") + .addOrderBy(`orgChild4.orgChild4ShortName`,body.descending ? "DESC" : "ASC") + .addOrderBy(`employeePosMaster.posMasterNo`,body.descending ? "DESC" : "ASC") + }else{ + query = query.orderBy( + `current_holder.${body.sortBy}`, + body.descending ? "DESC" : "ASC" + ); + } + }else{ + query = query.orderBy("current_holder.citizenId", "ASC") + } + + const [findPosMaster, total] = await query .skip((body.page - 1) * body.pageSize) .take(body.pageSize) .getManyAndCount(); + if (!findPosMaster) { throw new HttpError(HttpStatus.NOT_FOUND, "not found. PosMaster"); }