update sort test
This commit is contained in:
parent
c999b9cec7
commit
3f61b47314
1 changed files with 13 additions and 2 deletions
|
|
@ -45,13 +45,15 @@ export class DevelopmentRequestController extends Controller {
|
||||||
@Query("page") page: number = 1,
|
@Query("page") page: number = 1,
|
||||||
@Query("pageSize") pageSize: number = 10,
|
@Query("pageSize") pageSize: number = 10,
|
||||||
@Query("status") status?: string,
|
@Query("status") status?: string,
|
||||||
|
@Query("sortBy") sortBy?: string,
|
||||||
|
@Query("descending") descending?: boolean,
|
||||||
) {
|
) {
|
||||||
const profile = await this.profileRepository.findOneBy({ keycloak: req.user.sub });
|
const profile = await this.profileRepository.findOneBy({ keycloak: req.user.sub });
|
||||||
if (!profile) {
|
if (!profile) {
|
||||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
}
|
}
|
||||||
|
|
||||||
const [lists, total] = await AppDataSource.getRepository(DevelopmentRequest)
|
let query = await AppDataSource.getRepository(DevelopmentRequest)
|
||||||
.createQueryBuilder("developmentRequest")
|
.createQueryBuilder("developmentRequest")
|
||||||
.andWhere(
|
.andWhere(
|
||||||
status == undefined || status.trim().toUpperCase() == "ALL" || status == ""
|
status == undefined || status.trim().toUpperCase() == "ALL" || status == ""
|
||||||
|
|
@ -103,6 +105,15 @@ export class DevelopmentRequestController extends Controller {
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.orderBy("developmentRequest.createdAt", "DESC")
|
.orderBy("developmentRequest.createdAt", "DESC")
|
||||||
|
|
||||||
|
if (sortBy) {
|
||||||
|
query = query.orderBy(
|
||||||
|
`developmentRequest.${sortBy}`,
|
||||||
|
descending ? "DESC" : "ASC"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [lists, 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