fix: workflow query not work on filter (#3)

* fix: query not work when filter was applied

* refactor: prevent query condition from being build on empty
This commit is contained in:
Methapon Metanipat 2024-10-30 17:46:36 +07:00 committed by GitHub
parent 824727582d
commit 386ad956e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -24,6 +24,7 @@ import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status"; import HttpStatus from "../interfaces/http-status";
import { notFoundError } from "../utils/error"; import { notFoundError } from "../utils/error";
import { filterStatus } from "../services/prisma"; import { filterStatus } from "../services/prisma";
import { queryOrNot } from "../utils/relation";
type WorkflowPayload = { type WorkflowPayload = {
name: string; name: string;
@ -54,17 +55,19 @@ export class FlowTemplateController extends Controller {
@Query() query = "", @Query() query = "",
) { ) {
const where = { const where = {
OR: [ OR: queryOrNot(query, [
{ name: { contains: query } }, { name: { contains: query } },
{ {
step: { step: {
some: { name: { contains: query } }, some: { name: { contains: query } },
}, },
}, },
], ]),
...filterStatus(status), AND: {
registeredBranch: { ...filterStatus(status),
OR: permissionCondCompany(req.user), registeredBranch: {
OR: permissionCondCompany(req.user),
},
}, },
} satisfies Prisma.WorkflowTemplateWhereInput; } satisfies Prisma.WorkflowTemplateWhereInput;
const [result, total] = await prisma.$transaction([ const [result, total] = await prisma.$transaction([