From a9cf88d6d414479bd874d625b864e12e5a7502d9 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 19 Feb 2025 15:09:05 +0700 Subject: [PATCH] fix: query condition for get canceled work --- src/controllers/05-quotation-controller.ts | 22 ++++++++++++++----- src/controllers/06-request-list-controller.ts | 20 ++++++++++------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/controllers/05-quotation-controller.ts b/src/controllers/05-quotation-controller.ts index 034aa70..4555920 100644 --- a/src/controllers/05-quotation-controller.ts +++ b/src/controllers/05-quotation-controller.ts @@ -1,4 +1,4 @@ -import { PayCondition, Prisma, QuotationStatus, Status } from "@prisma/client"; +import { PayCondition, Prisma, QuotationStatus, RequestDataStatus, Status } from "@prisma/client"; import config from "../config.json"; import { Body, @@ -223,12 +223,22 @@ export class QuotationController extends Controller { requestData: hasCancel ? { some: { - requestWork: { - some: { - creditNoteId: null, - stepStatus: { some: { workStatus: RequestWorkStatus.Canceled } }, + OR: [ + { + requestDataStatus: RequestDataStatus.Canceled, + requestWork: { + some: { creditNoteId: null }, + }, }, - }, + { + requestWork: { + some: { + creditNoteId: null, + stepStatus: { some: { workStatus: RequestWorkStatus.Canceled } }, + }, + }, + }, + ], }, } : undefined, diff --git a/src/controllers/06-request-list-controller.ts b/src/controllers/06-request-list-controller.ts index b92a3f1..1f730cc 100644 --- a/src/controllers/06-request-list-controller.ts +++ b/src/controllers/06-request-list-controller.ts @@ -324,12 +324,6 @@ export class RequestListController extends Controller { }; } - if (cancelOnly) { - statusCondition = { - some: { workStatus: RequestWorkStatus.Canceled }, - }; - } - if (workStatus && !readyToTask && !cancelOnly) { statusCondition = { some: { workStatus }, @@ -337,8 +331,18 @@ export class RequestListController extends Controller { } const where = { - stepStatus: readyToTask || cancelOnly || workStatus ? statusCondition : undefined, - creditNote: cancelOnly ? null : undefined, + OR: cancelOnly + ? [ + { + stepStatus: { some: { workStatus: RequestWorkStatus.Canceled } }, + }, + { + request: { requestDataStatus: RequestDataStatus.Canceled }, + }, + ] + : undefined, + stepStatus: readyToTask || workStatus ? statusCondition : undefined, + creditNoteId: cancelOnly ? null : undefined, request: { id: requestDataId, requestDataStatus: readyToTask