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:
parent
824727582d
commit
386ad956e5
1 changed files with 8 additions and 5 deletions
|
|
@ -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([
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue