feat: filter branch by status
This commit is contained in:
parent
cbdb4c0e7a
commit
0893662536
2 changed files with 12 additions and 0 deletions
|
|
@ -22,6 +22,7 @@ import minio from "../services/minio";
|
|||
import { isSystem } from "../utils/keycloak";
|
||||
import { deleteFile, fileLocation, listFile } from "../utils/minio";
|
||||
import { createPermCheck } from "../services/permission";
|
||||
import { filterStatus } from "../services/prisma";
|
||||
|
||||
if (!process.env.MINIO_BUCKET) {
|
||||
throw Error("Require MinIO bucket.");
|
||||
|
|
@ -217,12 +218,14 @@ export class BranchController extends Controller {
|
|||
@Query() headOfficeId?: string,
|
||||
@Query() includeHead?: boolean,
|
||||
@Query() tree?: boolean,
|
||||
@Query() status?: Status,
|
||||
@Query() query: string = "",
|
||||
@Query() page: number = 1,
|
||||
@Query() pageSize: number = 30,
|
||||
) {
|
||||
const where = {
|
||||
AND: {
|
||||
...filterStatus(status),
|
||||
zipCode,
|
||||
headOfficeId: headOfficeId ?? (filter === "head" || tree ? null : undefined),
|
||||
NOT: { headOfficeId: filter === "sub" && !headOfficeId ? null : undefined },
|
||||
|
|
|
|||
9
src/services/prisma.ts
Normal file
9
src/services/prisma.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import { Status } from "@prisma/client";
|
||||
|
||||
export function filterStatus(val?: Status) {
|
||||
if (!val) return {};
|
||||
|
||||
return val !== Status.CREATED && val !== Status.ACTIVE
|
||||
? { status: val }
|
||||
: { OR: [{ status: Status.CREATED }, { status: Status.ACTIVE }] };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue