Compare commits

...

2 commits

Author SHA1 Message Date
HAM
e5a3d948a5 fix: missing query
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 5s
2025-09-17 12:39:10 +07:00
HAM
0d78ce4db3 feat: filter businessType, province, district, subDistrict for customer and customer-export endpoint 2025-09-17 12:37:41 +07:00

View file

@ -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;
@ -597,6 +642,10 @@ export class CustomerExportController extends CustomerController {
@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 ret = await this.list( const ret = await this.list(
req, req,
@ -610,6 +659,10 @@ export class CustomerExportController extends CustomerController {
activeBranchOnly, activeBranchOnly,
startDate, startDate,
endDate, endDate,
businessType,
province,
district,
subDistrict,
); );
this.setHeader("Content-Type", "text/csv"); this.setHeader("Content-Type", "text/csv");