From e9889a1682b9f55f07c72da054cd3f029b42f7e3 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 4 Mar 2025 13:42:01 +0700 Subject: [PATCH] fix: order --- src/controllers/00-stats-controller.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/controllers/00-stats-controller.ts b/src/controllers/00-stats-controller.ts index a9060a1..923696f 100644 --- a/src/controllers/00-stats-controller.ts +++ b/src/controllers/00-stats-controller.ts @@ -28,6 +28,7 @@ export class StatsController extends Controller { registeredBranch: { OR: permissionCondCompany(req.user) }, createdAt: { gte: startDate, lte: endDate }, }, + orderBy: { createdAt: 'desc' }, take: limit, }); @@ -64,6 +65,7 @@ export class StatsController extends Controller { }, createdAt: { gte: startDate, lte: endDate }, }, + orderBy: { createdAt: 'desc' }, take: limit, }); @@ -98,6 +100,7 @@ export class StatsController extends Controller { }, createdAt: { gte: startDate, lte: endDate }, }, + orderBy: { createdAt: 'desc' }, take: limit, }); @@ -117,6 +120,13 @@ export class StatsController extends Controller { @Query() endDate?: Date, ) { const record = await prisma.product.findMany({ + include: { + quotationProductServiceList: { + include: { + quotation: true, + }, + }, + }, select: { id: true, code: true, @@ -142,9 +152,15 @@ export class StatsController extends Controller { }, }, where: { - quotationProductServiceList: { some: {} }, + quotationProductServiceList: { + some: { + quotation: { createdAt: { gte: startDate, lte: endDate } }, + }, + }, productGroup: { registeredBranch: { OR: permissionCondCompany(req.user) } }, - createdAt: { gte: startDate, lte: endDate }, + }, + orderBy: { + quotationProductServiceList: { _count: "desc" }, }, take: limit, });