Merge branch 'develop'
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 4s

This commit is contained in:
Methapon2001 2025-09-18 10:15:36 +07:00
commit 0930c3c833
2 changed files with 61 additions and 20 deletions

View file

@ -170,10 +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() businessTypeId?: string,
@Query() province?: string, @Query() provinceId?: string,
@Query() district?: string, @Query() districtId?: string,
@Query() subDistrict?: string, @Query() subDistrictId?: string,
) { ) {
const where = { const where = {
OR: queryOrNot<Prisma.CustomerWhereInput[]>(query, [ OR: queryOrNot<Prisma.CustomerWhereInput[]>(query, [
@ -199,27 +199,27 @@ export class CustomerController extends Controller {
branch: { branch: {
some: { some: {
AND: [ 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() activeBranchOnly?: boolean,
@Query() startDate?: Date, @Query() startDate?: Date,
@Query() endDate?: Date, @Query() endDate?: Date,
@Query() businessType?: string, @Query() businessTypeId?: string,
@Query() province?: string, @Query() provinceId?: string,
@Query() district?: string, @Query() districtId?: string,
@Query() subDistrict?: string, @Query() subDistrictId?: string,
) { ) {
const ret = await this.list( const ret = await this.list(
req, req,
@ -647,10 +647,10 @@ export class CustomerExportController extends CustomerController {
activeBranchOnly, activeBranchOnly,
startDate, startDate,
endDate, endDate,
businessType, businessTypeId,
province, provinceId,
district, districtId,
subDistrict, subDistrictId,
); );
this.setHeader("Content-Type", "text/csv"); this.setHeader("Content-Type", "text/csv");

View file

@ -31,6 +31,7 @@ import { isUsedError, notFoundError, relationError } from "../utils/error";
import { queryOrNot, whereDateQuery } from "../utils/relation"; import { queryOrNot, whereDateQuery } from "../utils/relation";
import spreadsheet from "../utils/spreadsheet"; import spreadsheet from "../utils/spreadsheet";
import flowAccount from "../services/flowaccount"; import flowAccount from "../services/flowaccount";
import { json2csv } from "json-2-csv";
const MANAGE_ROLES = [ const MANAGE_ROLES = [
"system", "system",
@ -673,3 +674,43 @@ export class ProductFileController extends Controller {
return await deleteFile(fileLocation.product.img(productId, name)); 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 });
}
}