From f50285161b02142019469e089f186b20cec6e511 Mon Sep 17 00:00:00 2001 From: HAM Date: Thu, 18 Sep 2025 10:13:39 +0700 Subject: [PATCH 1/2] fix: variable name for filter --- src/controllers/03-customer-controller.ts | 40 +++++++++++------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/controllers/03-customer-controller.ts b/src/controllers/03-customer-controller.ts index 95e2df6..bd3bc4d 100644 --- a/src/controllers/03-customer-controller.ts +++ b/src/controllers/03-customer-controller.ts @@ -170,10 +170,10 @@ export class CustomerController extends Controller { @Query() activeBranchOnly?: boolean, @Query() startDate?: Date, @Query() endDate?: Date, - @Query() businessType?: string, - @Query() province?: string, - @Query() district?: string, - @Query() subDistrict?: string, + @Query() businessTypeId?: string, + @Query() provinceId?: string, + @Query() districtId?: string, + @Query() subDistrictId?: string, ) { const where = { OR: queryOrNot(query, [ @@ -199,27 +199,27 @@ export class CustomerController extends Controller { branch: { some: { AND: [ - businessType + businessTypeId ? { - OR: [{ businessType: { id: businessType } }], + OR: [{ businessType: { id: businessTypeId } }], } : {}, - province + provinceId ? { - OR: [{ province: { id: province } }], + OR: [{ province: { id: provinceId } }], } : {}, - district + districtId ? { - OR: [{ district: { id: district } }], + OR: [{ district: { id: districtId } }], } : {}, - subDistrict + subDistrictId ? { - OR: [{ subDistrict: { id: subDistrict } }], + OR: [{ subDistrict: { id: subDistrictId } }], } : {}, ], @@ -630,10 +630,10 @@ export class CustomerExportController extends CustomerController { @Query() activeBranchOnly?: boolean, @Query() startDate?: Date, @Query() endDate?: Date, - @Query() businessType?: string, - @Query() province?: string, - @Query() district?: string, - @Query() subDistrict?: string, + @Query() businessTypeId?: string, + @Query() provinceId?: string, + @Query() districtId?: string, + @Query() subDistrictId?: string, ) { const ret = await this.list( req, @@ -647,10 +647,10 @@ export class CustomerExportController extends CustomerController { activeBranchOnly, startDate, endDate, - businessType, - province, - district, - subDistrict, + businessTypeId, + provinceId, + districtId, + subDistrictId, ); this.setHeader("Content-Type", "text/csv"); From be3c6405c685d8f727af21afb1ef45b0b968074b Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 18 Sep 2025 10:15:32 +0700 Subject: [PATCH 2/2] feat: export product --- src/controllers/04-product-controller.ts | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/controllers/04-product-controller.ts b/src/controllers/04-product-controller.ts index c1c40d8..612275e 100644 --- a/src/controllers/04-product-controller.ts +++ b/src/controllers/04-product-controller.ts @@ -31,6 +31,7 @@ import { isUsedError, notFoundError, relationError } from "../utils/error"; import { queryOrNot, whereDateQuery } from "../utils/relation"; import spreadsheet from "../utils/spreadsheet"; import flowAccount from "../services/flowaccount"; +import { json2csv } from "json-2-csv"; const MANAGE_ROLES = [ "system", @@ -673,3 +674,43 @@ export class ProductFileController extends Controller { return await deleteFile(fileLocation.product.img(productId, name)); } } + +@Route("api/v1/product-export") +@Tags("Product") +export class ProductExportController extends ProductController { + @Get() + @Security("keycloak") + async exportCustomer( + @Request() req: RequestWithUser, + @Query() status?: Status, + @Query() shared?: boolean, + @Query() productGroupId?: string, + @Query() query: string = "", + @Query() page: number = 1, + @Query() pageSize: number = 30, + @Query() orderField?: keyof Product, + @Query() orderBy?: "asc" | "desc", + @Query() activeOnly?: boolean, + @Query() startDate?: Date, + @Query() endDate?: Date, + ) { + const ret = await this.getProduct( + req, + status, + shared, + productGroupId, + query, + page, + pageSize, + orderField, + orderBy, + activeOnly, + startDate, + endDate, + ); + + this.setHeader("Content-Type", "text/csv"); + + return json2csv(ret.result, { useDateIso8601Format: true, expandNestedObjects: true }); + } +}