From 5be36351986530443db647c9fc6879afe22b69a7 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 29 Sep 2025 17:33:22 +0700 Subject: [PATCH] no message --- src/controllers/CommandController.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 6a4a2e3f..4e5f898e 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -160,6 +160,8 @@ export class CommandController extends Controller { @Get("list") async GetResult( @Request() request: RequestWithUser, + @Query("sortBy") sortBy?: string, + @Query("descending") descending?: boolean, @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Query() keyword: string = "", @@ -262,14 +264,9 @@ export class CommandController extends Controller { yearKeyword = match[1].trim(); } let yearInBC = yearKeyword ? parseInt(yearKeyword) - 543 : null; - // - - // console.log("k>>",keyword); - // console.log("bk>>",baseKeyword); - // console.log("yk>>",yearKeyword); - // console.log("yi>>",yearInBC); - - const [commands, total] = await this.commandRepository + + // const [commands, total] = await this.commandRepository + let query = await this.commandRepository .createQueryBuilder("command") .leftJoinAndSelect("command.commandType", "commandType") .andWhere( @@ -339,6 +336,15 @@ export class CommandController extends Controller { }), ) .orderBy("command.createdAt", "DESC") + + if (sortBy) { + query = query.orderBy( + `command.${sortBy}`, + descending ? "DESC" : "ASC" + ); + } + + let [commands, total] = await query .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount();