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