This commit is contained in:
Adisak 2025-09-30 15:15:57 +07:00
parent 58e44de196
commit 2a9f69f736

View file

@ -8567,6 +8567,8 @@ export class ProfileController extends Controller {
keyword?: string;
system?: string;
},
@Query("sortBy") sortBy?: string,
@Query("descending") descending?: boolean
) {
// ค้นหารายชื่อถ้าไม่ส่ง system มาให้ default ตามทะเบียนประวัติ
let _system: string = "SYS_REGISTRY_OFFICER";
@ -8638,7 +8640,7 @@ export class ProfileController extends Controller {
break;
}
const [findProfile, total] = await this.profileRepo
let query = await this.profileRepo
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.posType", "posType")
.leftJoinAndSelect("profile.posLevel", "posLevel")
@ -8694,6 +8696,27 @@ export class ProfileController extends Controller {
qb.orWhere(body.keyword ? queryLike : "1=1", { keyword: `%${body.keyword}%` });
}),
)
if (sortBy) {
if(sortBy === "name"){
query = query
.orderBy(`profile.prefix`,descending ? "DESC" : "ASC")
.addOrderBy(`profile.firstName`,descending ? "DESC" : "ASC")
.addOrderBy(`profile.lastName`,descending ? "DESC" : "ASC")
}else if(sortBy === "organization"){
query = query.orderBy(
`orgRoot.orgRootName`,
descending ? "DESC" : "ASC"
);
}else{
query = query.orderBy(
`profile.${sortBy}`,
descending ? "DESC" : "ASC"
);
}
}
const [findProfile, total] = await query
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();