From c9c14f052b289f103efe7621dbabc24faa13bad4 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 15 May 2024 15:29:12 +0700 Subject: [PATCH] orderBy --- src/controllers/BloodGroupController.ts | 2 +- src/controllers/GenderController.ts | 2 +- src/controllers/PosExecutiveController.ts | 1 + src/controllers/PositionController.ts | 11 +++++++++++ src/controllers/PrefixController.ts | 2 +- src/controllers/RankController.ts | 2 +- src/controllers/RelationshipController.ts | 2 +- src/controllers/ReligionController.ts | 2 +- 8 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/controllers/BloodGroupController.ts b/src/controllers/BloodGroupController.ts index bffb007d..815d7603 100644 --- a/src/controllers/BloodGroupController.ts +++ b/src/controllers/BloodGroupController.ts @@ -142,7 +142,7 @@ export class BloodGroupController extends Controller { async listBloodGroup() { const bloodGroup = await this.bloodGroupRepository.find({ select: ["id", "name", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"], - order: { createdAt: "ASC" }, + order: { name: "ASC" }, }); // if (!bloodGroup) { diff --git a/src/controllers/GenderController.ts b/src/controllers/GenderController.ts index 841380c1..c9e33785 100644 --- a/src/controllers/GenderController.ts +++ b/src/controllers/GenderController.ts @@ -41,7 +41,7 @@ export class GenderController extends Controller { async GetResult() { const _gender = await this.genderRepository.find({ select: ["id", "name", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"], - order: { createdAt: "ASC" }, + order: { name: "ASC" }, }); // if (!_gender) { // return new HttpSuccess([]); diff --git a/src/controllers/PosExecutiveController.ts b/src/controllers/PosExecutiveController.ts index eee0e55e..dcab6724 100644 --- a/src/controllers/PosExecutiveController.ts +++ b/src/controllers/PosExecutiveController.ts @@ -199,6 +199,7 @@ export class PosExecutiveController extends Controller { async GetPosExecutive() { const posExecutive = await this.posExecutiveRepository.find({ select: ["id", "posExecutiveName", "posExecutivePriority"], + order: { posExecutivePriority: "ASC" }, }); // if (!posExecutive) { // return new HttpSuccess([]); diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index da545b3e..05160272 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -352,6 +352,7 @@ export class PositionController extends Controller { findPosDict = await this.posDictRepository.find({ where: { posDictName: Like(`%${keyword}%`) }, relations: ["posType", "posLevel", "posExecutive"], + order: { posDictName: "ASC" }, }); // if (!findPosDict) { // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword); @@ -362,6 +363,7 @@ export class PositionController extends Controller { findPosDict = await this.posDictRepository.find({ where: { posDictField: Like(`%${keyword}%`) }, relations: ["posType", "posLevel", "posExecutive"], + order: { posDictField: "ASC" }, }); // if (!findPosDict) { // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword); @@ -371,33 +373,39 @@ export class PositionController extends Controller { case "positionType": const findTypes: PosType[] = await this.posTypeRepository.find({ where: { posTypeName: Like(`%${keyword}%`) }, + order: { posTypeName: "ASC" }, select: ["id"], }); findPosDict = await this.posDictRepository.find({ where: { posTypeId: In(findTypes.map((x) => x.id)) }, relations: ["posType", "posLevel", "posExecutive"], + order: { posDictName: "ASC" }, }); break; case "positionLevel": const findLevel: PosLevel[] = await this.posLevelRepository.find({ where: { posLevelName: Like(`%${keyword}%`) }, + order: { posLevelName: "ASC" }, select: ["id"], }); findPosDict = await this.posDictRepository.find({ where: { posLevelId: In(findLevel.map((x) => x.id)) }, relations: ["posType", "posLevel", "posExecutive"], + order: { posDictName: "ASC" }, }); break; case "positionExecutive": const findExecutive: PosExecutive[] = await this.posExecutiveRepository.find({ where: { posExecutiveName: Like(`%${keyword}%`) }, + order: { posExecutiveName: "ASC" }, select: ["id"], }); findPosDict = await this.posDictRepository.find({ where: { posExecutiveId: In(findExecutive.map((x) => x.id)) }, relations: ["posType", "posLevel", "posExecutive"], + order: { posDictName: "ASC" }, }); break; @@ -405,6 +413,7 @@ export class PositionController extends Controller { findPosDict = await this.posDictRepository.find({ where: { posDictExecutiveField: Like(`%${keyword}%`) }, relations: ["posType", "posLevel", "posExecutive"], + order: { posDictName: "ASC" }, }); // if (!findPosDict) { // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword); @@ -415,6 +424,7 @@ export class PositionController extends Controller { findPosDict = await this.posDictRepository.find({ where: { posDictArea: Like(`%${keyword}%`) }, relations: ["posType", "posLevel", "posExecutive"], + order: { posDictName: "ASC" }, }); // if (!findPosDict) { // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword); @@ -424,6 +434,7 @@ export class PositionController extends Controller { default: findPosDict = await this.posDictRepository.find({ relations: ["posType", "posLevel", "posExecutive"], + order: { posDictName: "ASC" }, }); // if (!findPosDict) { // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); diff --git a/src/controllers/PrefixController.ts b/src/controllers/PrefixController.ts index 27941f43..4f0cbedd 100644 --- a/src/controllers/PrefixController.ts +++ b/src/controllers/PrefixController.ts @@ -41,7 +41,7 @@ export class PrefixController extends Controller { async Get() { const _prefix = await this.prefixRepository.find({ select: ["id", "name", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"], - order: { createdAt: "ASC" }, + order: { name: "ASC" }, }); // if (!_prefix) { // return new HttpSuccess([]); diff --git a/src/controllers/RankController.ts b/src/controllers/RankController.ts index 6f4018d9..32c002ba 100644 --- a/src/controllers/RankController.ts +++ b/src/controllers/RankController.ts @@ -141,7 +141,7 @@ export class RankController extends Controller { async listRank() { const rank = await this.rankRepository.find({ select: ["id", "name", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"], - order: { createdAt: "ASC" }, + order: { name: "ASC" }, }); // if (!rank) { diff --git a/src/controllers/RelationshipController.ts b/src/controllers/RelationshipController.ts index 81baef95..b43b5e3e 100644 --- a/src/controllers/RelationshipController.ts +++ b/src/controllers/RelationshipController.ts @@ -141,7 +141,7 @@ export class RelationshipController extends Controller { async listRelationship() { const relationship = await this.relationshipRepository.find({ select: ["id", "name", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"], - order: { createdAt: "ASC" }, + order: { name: "ASC" }, }); // if (!relationship) { // return new HttpSuccess([]); diff --git a/src/controllers/ReligionController.ts b/src/controllers/ReligionController.ts index 5bfea001..b3fdbed7 100644 --- a/src/controllers/ReligionController.ts +++ b/src/controllers/ReligionController.ts @@ -141,7 +141,7 @@ export class ReligionController extends Controller { async listReligion() { const religion = await this.religionRepository.find({ select: ["id", "name", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"], - order: { createdAt: "ASC" }, + order: { name: "ASC" }, }); // if (!religion) {