feat: filter by branch type (head/sub) and relation
This commit is contained in:
parent
818112fff4
commit
24c85b728c
1 changed files with 22 additions and 2 deletions
|
|
@ -20,7 +20,7 @@ import HttpStatus from "../../interfaces/http-status";
|
|||
import { RequestWithUser } from "../../interfaces/user";
|
||||
|
||||
type BranchCreate = {
|
||||
code: string;
|
||||
code?: string;
|
||||
taxNo: string;
|
||||
nameEN: string;
|
||||
name: string;
|
||||
|
|
@ -85,11 +85,17 @@ export class BranchController extends Controller {
|
|||
@Get()
|
||||
async getBranch(
|
||||
@Query() zipCode?: string,
|
||||
@Query() filter?: "head" | "sub",
|
||||
@Query() tree?: boolean,
|
||||
@Query() query: string = "",
|
||||
@Query() page: number = 1,
|
||||
@Query() pageSize: number = 30,
|
||||
) {
|
||||
const where = {
|
||||
AND: {
|
||||
headOfficeId: filter === "head" || tree ? null : undefined,
|
||||
NOT: { headOfficeId: filter === "sub" ? null : undefined },
|
||||
},
|
||||
OR: [
|
||||
{ nameEN: { contains: query }, zipCode },
|
||||
{ name: { contains: query }, zipCode },
|
||||
|
|
@ -103,6 +109,13 @@ export class BranchController extends Controller {
|
|||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
branch: tree && {
|
||||
include: {
|
||||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
where,
|
||||
take: pageSize,
|
||||
|
|
@ -115,12 +128,19 @@ export class BranchController extends Controller {
|
|||
}
|
||||
|
||||
@Get("{branchId}")
|
||||
async getBranchById(@Path() branchId: string) {
|
||||
async getBranchById(@Path() branchId: string, @Query() includeSubBranch: boolean) {
|
||||
const record = await prisma.branch.findFirst({
|
||||
include: {
|
||||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
branch: includeSubBranch && {
|
||||
include: {
|
||||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
where: { id: branchId },
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue