feat: filter businessType, province, district, subDistrict for customer and customer-export endpoint
This commit is contained in:
parent
ab4ea4ba4b
commit
0d78ce4db3
1 changed files with 45 additions and 0 deletions
|
|
@ -170,6 +170,10 @@ export class CustomerController extends Controller {
|
||||||
@Query() activeBranchOnly?: boolean,
|
@Query() activeBranchOnly?: boolean,
|
||||||
@Query() startDate?: Date,
|
@Query() startDate?: Date,
|
||||||
@Query() endDate?: Date,
|
@Query() endDate?: Date,
|
||||||
|
@Query() businessType?: string,
|
||||||
|
@Query() province?: string,
|
||||||
|
@Query() district?: string,
|
||||||
|
@Query() subDistrict?: string,
|
||||||
) {
|
) {
|
||||||
const where = {
|
const where = {
|
||||||
OR: queryOrNot<Prisma.CustomerWhereInput[]>(query, [
|
OR: queryOrNot<Prisma.CustomerWhereInput[]>(query, [
|
||||||
|
|
@ -192,6 +196,47 @@ export class CustomerController extends Controller {
|
||||||
: permissionCond(req.user, { activeOnly: activeBranchOnly }),
|
: permissionCond(req.user, { activeOnly: activeBranchOnly }),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
branch: {
|
||||||
|
some: {
|
||||||
|
AND: [
|
||||||
|
businessType
|
||||||
|
? {
|
||||||
|
OR: [
|
||||||
|
{ businessType: { name: { contains: businessType, mode: "insensitive" } } },
|
||||||
|
{ businessType: { nameEN: { contains: businessType, mode: "insensitive" } } },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
: {},
|
||||||
|
|
||||||
|
province
|
||||||
|
? {
|
||||||
|
OR: [
|
||||||
|
{ province: { name: { contains: province, mode: "insensitive" } } },
|
||||||
|
{ province: { nameEN: { contains: province, mode: "insensitive" } } },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
: {},
|
||||||
|
|
||||||
|
district
|
||||||
|
? {
|
||||||
|
OR: [
|
||||||
|
{ district: { name: { contains: district, mode: "insensitive" } } },
|
||||||
|
{ district: { nameEN: { contains: district, mode: "insensitive" } } },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
: {},
|
||||||
|
|
||||||
|
subDistrict
|
||||||
|
? {
|
||||||
|
OR: [
|
||||||
|
{ subDistrict: { name: { contains: subDistrict, mode: "insensitive" } } },
|
||||||
|
{ subDistrict: { nameEN: { contains: subDistrict, mode: "insensitive" } } },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
: {},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
...whereDateQuery(startDate, endDate),
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.CustomerWhereInput;
|
} satisfies Prisma.CustomerWhereInput;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue