sort
This commit is contained in:
parent
58e44de196
commit
2a9f69f736
1 changed files with 24 additions and 1 deletions
|
|
@ -8567,6 +8567,8 @@ export class ProfileController extends Controller {
|
||||||
keyword?: string;
|
keyword?: string;
|
||||||
system?: string;
|
system?: string;
|
||||||
},
|
},
|
||||||
|
@Query("sortBy") sortBy?: string,
|
||||||
|
@Query("descending") descending?: boolean
|
||||||
) {
|
) {
|
||||||
// ค้นหารายชื่อถ้าไม่ส่ง system มาให้ default ตามทะเบียนประวัติ
|
// ค้นหารายชื่อถ้าไม่ส่ง system มาให้ default ตามทะเบียนประวัติ
|
||||||
let _system: string = "SYS_REGISTRY_OFFICER";
|
let _system: string = "SYS_REGISTRY_OFFICER";
|
||||||
|
|
@ -8638,7 +8640,7 @@ export class ProfileController extends Controller {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [findProfile, total] = await this.profileRepo
|
let query = await this.profileRepo
|
||||||
.createQueryBuilder("profile")
|
.createQueryBuilder("profile")
|
||||||
.leftJoinAndSelect("profile.posType", "posType")
|
.leftJoinAndSelect("profile.posType", "posType")
|
||||||
.leftJoinAndSelect("profile.posLevel", "posLevel")
|
.leftJoinAndSelect("profile.posLevel", "posLevel")
|
||||||
|
|
@ -8694,6 +8696,27 @@ export class ProfileController extends Controller {
|
||||||
qb.orWhere(body.keyword ? queryLike : "1=1", { keyword: `%${body.keyword}%` });
|
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)
|
.skip((page - 1) * pageSize)
|
||||||
.take(pageSize)
|
.take(pageSize)
|
||||||
.getManyAndCount();
|
.getManyAndCount();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue