feat: export customer and employee as csv
This commit is contained in:
parent
d95eb349ec
commit
ab8fd2ca43
2 changed files with 95 additions and 1 deletions
|
|
@ -37,6 +37,7 @@ import {
|
|||
} from "../utils/minio";
|
||||
import { isUsedError, notFoundError, relationError } from "../utils/error";
|
||||
import { connectOrNot, queryOrNot, whereDateQuery } from "../utils/relation";
|
||||
import { json2csv } from "json-2-csv";
|
||||
|
||||
const MANAGE_ROLES = [
|
||||
"system",
|
||||
|
|
@ -547,3 +548,44 @@ export class CustomerImageController extends Controller {
|
|||
await deleteFile(fileLocation.customer.img(customerId, name));
|
||||
}
|
||||
}
|
||||
|
||||
@Route("api/v1/customer-export")
|
||||
@Tags("Customer")
|
||||
export class CustomerExportController extends CustomerController {
|
||||
@Get()
|
||||
@Security("keycloak")
|
||||
async exportCustomer(
|
||||
@Request() req: RequestWithUser,
|
||||
@Query() customerType?: CustomerType,
|
||||
@Query() query: string = "",
|
||||
@Query() status?: Status,
|
||||
@Query() page: number = 1,
|
||||
@Query() pageSize: number = 30,
|
||||
@Query() includeBranch: boolean = false,
|
||||
@Query() company: boolean = false,
|
||||
@Query() activeBranchOnly?: boolean,
|
||||
@Query() startDate?: Date,
|
||||
@Query() endDate?: Date,
|
||||
) {
|
||||
const ret = await this.list(
|
||||
req,
|
||||
customerType,
|
||||
query,
|
||||
status,
|
||||
page,
|
||||
pageSize,
|
||||
includeBranch,
|
||||
company,
|
||||
activeBranchOnly,
|
||||
startDate,
|
||||
endDate,
|
||||
);
|
||||
|
||||
this.setHeader("Content-Type", "text/csv");
|
||||
|
||||
return json2csv(
|
||||
ret.result.map((v) => Object.assign(v, { branch: v.branch.at(0) ?? null })),
|
||||
{ useDateIso8601Format: true, expandNestedObjects: true },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue