diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 81781adf..800dc72d 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -9103,6 +9103,8 @@ export class ProfileController extends Controller { page: number; pageSize: number; keyword?: string; + sortBy?: string; + descending?: boolean; }, ) { let _data: any = { @@ -9116,7 +9118,7 @@ export class ProfileController extends Controller { if (!request.user.role.includes("SUPER_ADMIN")) { _data = await new permission().PermissionOrgCreate(request, "SYS_PROBATION"); } - const [findProfile, total] = await AppDataSource.getRepository(Profile) + let query = await AppDataSource.getRepository(Profile) .createQueryBuilder("profile") .leftJoinAndSelect("profile.profileSalary", "profileSalary") .leftJoinAndSelect("profile.posLevel", "posLevel") @@ -9230,7 +9232,34 @@ export class ProfileController extends Controller { ); }), ) - .orderBy("profile.citizenId", "ASC") + + if (body.sortBy) { + if(body.sortBy === "posLevelName"){ + query = query.orderBy( + `posLevel.posLevelName`, + body.descending ? "DESC" : "ASC" + ); + }else if(body.sortBy === "posTypeName"){ + query = query.orderBy( + `posType.posTypeName`, + body.descending ? "DESC" : "ASC" + ); + }else if(body.sortBy === "commandNo"){ + query = query.orderBy( + `profileSalary.commandNo`, + body.descending ? "DESC" : "ASC" + ); + }else{ + query = query.orderBy( + `profile.${body.sortBy}`, + body.descending ? "DESC" : "ASC" + ); + } + }else{ + query = query.orderBy("profile.citizenId", "ASC") + } + + const [findProfile, total] = await query .skip((body.page - 1) * body.pageSize) .take(body.pageSize) .getManyAndCount();