refactor(ProfileController): add subquery to sortBy commandNo for Post probation API
This commit is contained in:
parent
0ba5e36a4f
commit
a532fcf23d
1 changed files with 13 additions and 1 deletions
|
|
@ -10049,7 +10049,19 @@ export class ProfileController extends Controller {
|
|||
} 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");
|
||||
// Use subquery to get the latest commandNo for each profile
|
||||
const subquery = AppDataSource.getRepository(ProfileSalary)
|
||||
.createQueryBuilder("ps")
|
||||
.select("ps.commandNo", "commandNo")
|
||||
.where("ps.profileId = profile.id")
|
||||
.orderBy("ps.order", "DESC")
|
||||
.addOrderBy("ps.commandNo", "DESC")
|
||||
.limit(1);
|
||||
|
||||
query = query
|
||||
.addSelect(`(${subquery.getSql()})`, "latestCommandNo")
|
||||
.orderBy("latestCommandNo", body.descending ? "DESC" : "ASC")
|
||||
.addOrderBy("profile.id", "ASC"); // Secondary sort for consistency
|
||||
} else if (body.sortBy === "orgRootName") {
|
||||
query = query.orderBy(`orgRoot.orgRootName`, body.descending ? "DESC" : "ASC");
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue