From 0fa198a7719abd9896454b5084f59197f6343e14 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 27 Nov 2024 10:37:26 +0700 Subject: [PATCH] =?UTF-8?q?sort=20=E0=B8=88=E0=B8=B1=E0=B8=87=E0=B8=AB?= =?UTF-8?q?=E0=B8=A7=E0=B8=B1=E0=B8=94=20=E0=B8=AD=E0=B8=B3=E0=B9=80?= =?UTF-8?q?=E0=B8=A0=E0=B8=AD=20=E0=B8=95=E0=B8=B3=E0=B8=9A=E0=B8=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DistrictController.ts | 15 +++++++++++++-- src/controllers/ProvinceController.ts | 15 +++++++++++++-- src/controllers/SubDistrictController.ts | 5 ++++- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/controllers/DistrictController.ts b/src/controllers/DistrictController.ts index 6817aa5a..2e57930f 100644 --- a/src/controllers/DistrictController.ts +++ b/src/controllers/DistrictController.ts @@ -43,7 +43,10 @@ export class DistrictController extends Controller { async GetResult() { const _district = await this.districtRepository.find({ select: ["id", "name", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"], - order: { name: "ASC" }, + order: { + name: "ASC", + createdAt: "DESC" + }, }); return new HttpSuccess(_district); } @@ -59,8 +62,16 @@ export class DistrictController extends Controller { async GetById(@Path() id: string) { const _district = await this.districtRepository.findOne({ where: { id }, - select: ["id", "name"], + select: ["id", "name", "createdAt"], relations: { subDistricts: true }, + order: { + name: "ASC", + createdAt: "DESC", + subDistricts: { + name: "ASC", + createdAt: "DESC" + } + } }); if (!_district) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเขตนี้"); diff --git a/src/controllers/ProvinceController.ts b/src/controllers/ProvinceController.ts index 6d4574f6..e7916cdf 100644 --- a/src/controllers/ProvinceController.ts +++ b/src/controllers/ProvinceController.ts @@ -41,7 +41,10 @@ export class ProvinceController extends Controller { async GetResult() { const _province = await this.provinceRepository.find({ select: ["id", "name", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"], - order: { createdAt: "DESC" }, + order: { + name: "ASC", + createdAt: "DESC" + }, }); return new HttpSuccess(_province); } @@ -57,8 +60,16 @@ export class ProvinceController extends Controller { async GetById(@Path() id: string) { const _province = await this.provinceRepository.findOne({ where: { id }, - select: ["id", "name"], + select: ["id", "name", "createdAt"], relations: { districts: true }, + order: { + name: "ASC", + createdAt: "DESC", + districts: { + name: "ASC", + createdAt: "DESC" + } + }, }); if (!_province) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดนี้"); diff --git a/src/controllers/SubDistrictController.ts b/src/controllers/SubDistrictController.ts index 8c329354..4f653220 100644 --- a/src/controllers/SubDistrictController.ts +++ b/src/controllers/SubDistrictController.ts @@ -43,7 +43,10 @@ export class SubDistrictController extends Controller { async GetResult() { const _subDistrict = await this.subDistrictRepository.find({ select: ["id", "name", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"], - order: { name: "ASC" }, + order: { + name: "ASC", + createdAt: "DESC" + }, }); return new HttpSuccess(_subDistrict); }