From 09cf32d3c7ebdc8da78c384c87bff2889a97879e Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Mon, 24 Jun 2024 13:20:59 +0700 Subject: [PATCH] feat: order by status field --- src/controllers/customer-branch-controller.ts | 2 +- src/controllers/customer-controller.ts | 2 +- src/controllers/employee-controller.ts | 2 +- src/controllers/product/group-controller.ts | 5 ++++- src/controllers/product/product-controller.ts | 2 +- src/controllers/product/type-controller.ts | 5 ++++- src/controllers/service/service-controller.ts | 2 +- src/controllers/user-controller.ts | 2 +- 8 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/controllers/customer-branch-controller.ts b/src/controllers/customer-branch-controller.ts index 0b6b5cb..ff7eac6 100644 --- a/src/controllers/customer-branch-controller.ts +++ b/src/controllers/customer-branch-controller.ts @@ -152,7 +152,7 @@ export class CustomerBranchController extends Controller { const [result, total] = await prisma.$transaction([ prisma.customerBranch.findMany({ - orderBy: { createdAt: "asc" }, + orderBy: [{ statusOrder: "asc" }, { createdAt: "asc" }], include: { customer: includeCustomer, province: true, diff --git a/src/controllers/customer-controller.ts b/src/controllers/customer-controller.ts index 3798e89..6b712cc 100644 --- a/src/controllers/customer-controller.ts +++ b/src/controllers/customer-controller.ts @@ -175,7 +175,7 @@ export class CustomerController extends Controller { } : undefined, }, - orderBy: { createdAt: "asc" }, + orderBy: [{ statusOrder: "asc" }, { createdAt: "asc" }], where, take: pageSize, skip: (page - 1) * pageSize, diff --git a/src/controllers/employee-controller.ts b/src/controllers/employee-controller.ts index f0e11db..edb780b 100644 --- a/src/controllers/employee-controller.ts +++ b/src/controllers/employee-controller.ts @@ -253,7 +253,7 @@ export class EmployeeController extends Controller { const [result, total] = await prisma.$transaction([ prisma.employee.findMany({ - orderBy: { createdAt: "asc" }, + orderBy: [{ statusOrder: "asc" }, { createdAt: "asc" }], include: { province: true, district: true, diff --git a/src/controllers/product/group-controller.ts b/src/controllers/product/group-controller.ts index f27b7e1..c57e767 100644 --- a/src/controllers/product/group-controller.ts +++ b/src/controllers/product/group-controller.ts @@ -58,7 +58,10 @@ export class ProductGroup extends Controller { { detail: { contains: query }, ...filterStatus(status) }, ], } satisfies Prisma.ProductGroupWhereInput; - return prisma.productGroup.findMany({ orderBy: { createdAt: "asc" }, where }); + return prisma.productGroup.findMany({ + orderBy: [{ statusOrder: "asc" }, { createdAt: "asc" }], + where, + }); } @Get("{groupId}") diff --git a/src/controllers/product/product-controller.ts b/src/controllers/product/product-controller.ts index 3c71ad2..79bf0da 100644 --- a/src/controllers/product/product-controller.ts +++ b/src/controllers/product/product-controller.ts @@ -89,7 +89,7 @@ export class ProductController extends Controller { const [result, total] = await prisma.$transaction([ prisma.product.findMany({ - orderBy: { createdAt: "asc" }, + orderBy: [{ statusOrder: "asc" }, { createdAt: "asc" }], where, take: pageSize, skip: (page - 1) * pageSize, diff --git a/src/controllers/product/type-controller.ts b/src/controllers/product/type-controller.ts index 89d5a22..b88d668 100644 --- a/src/controllers/product/type-controller.ts +++ b/src/controllers/product/type-controller.ts @@ -64,7 +64,10 @@ export class ProductType extends Controller { { detail: { contains: query }, ...filterStatus(status) }, ], } satisfies Prisma.ProductTypeWhereInput; - const result = prisma.productType.findMany({ orderBy: { createdAt: "asc" }, where }); + const result = prisma.productType.findMany({ + orderBy: [{ statusOrder: "asc" }, { createdAt: "asc" }], + where, + }); return result; } diff --git a/src/controllers/service/service-controller.ts b/src/controllers/service/service-controller.ts index ddfdee2..70ea3bf 100644 --- a/src/controllers/service/service-controller.ts +++ b/src/controllers/service/service-controller.ts @@ -82,7 +82,7 @@ export class ServiceController extends Controller { include: { work: true, }, - orderBy: { createdAt: "asc" }, + orderBy: [{ statusOrder: "asc" }, { createdAt: "asc" }], where, take: pageSize, skip: (page - 1) * pageSize, diff --git a/src/controllers/user-controller.ts b/src/controllers/user-controller.ts index fdfb338..73f0ef4 100644 --- a/src/controllers/user-controller.ts +++ b/src/controllers/user-controller.ts @@ -166,7 +166,7 @@ export class UserController extends Controller { const [result, total] = await prisma.$transaction([ prisma.user.findMany({ - orderBy: { createdAt: "asc" }, + orderBy: [{ statusOrder: "asc" }, { createdAt: "asc" }], include: { province: true, district: true,