From 1c297d47cf6406110f0a40bec3affeafb764f3b0 Mon Sep 17 00:00:00 2001 From: Adisak Date: Tue, 30 Sep 2025 14:45:05 +0700 Subject: [PATCH] sort eva MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ประเมินบุคคล>>คำขอประเมิน --- src/controllers/EvaluationController.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/controllers/EvaluationController.ts b/src/controllers/EvaluationController.ts index 1d77bf9..8c0b90c 100644 --- a/src/controllers/EvaluationController.ts +++ b/src/controllers/EvaluationController.ts @@ -145,6 +145,8 @@ export class EvaluationController { pageSize: number; keyword?: string; status?: string[]; + sortBy?: string; + descending?: boolean; }, ) { try { @@ -156,7 +158,7 @@ export class EvaluationController { _data = x; }) .catch((x) => {}); - const [evaluation, total] = await AppDataSource.getRepository(Evaluation) + let query = await AppDataSource.getRepository(Evaluation) .createQueryBuilder("evaluation") .andWhere( _data.root != undefined && _data.root != null @@ -233,7 +235,17 @@ export class EvaluationController { ); }), ) - .orderBy("evaluation.lastUpdatedAt", "DESC") + + if (body.sortBy) { + query = query.orderBy( + `evaluation.${body.sortBy}`, + body.descending ? "DESC" : "ASC" + ); + }else{ + query = query.orderBy("evaluation.lastUpdatedAt", "DESC") + } + + const [evaluation, total] = await query .skip((body.page - 1) * body.pageSize) .take(body.pageSize) .getManyAndCount();