feat: export customer and employee as csv
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 5s
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 5s
This commit is contained in:
parent
35a7f809e1
commit
b89c68425c
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 },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ import {
|
|||
listFile,
|
||||
setFile,
|
||||
} from "../utils/minio";
|
||||
import { json2csv } from "json-2-csv";
|
||||
|
||||
if (!process.env.MINIO_BUCKET) {
|
||||
throw Error("Require MinIO bucket.");
|
||||
|
|
@ -249,7 +250,6 @@ export class EmployeeController extends Controller {
|
|||
endDate,
|
||||
);
|
||||
}
|
||||
|
||||
@Post("list")
|
||||
@Security("keycloak")
|
||||
async listByCriteria(
|
||||
|
|
@ -927,3 +927,55 @@ export class EmployeeFileController extends Controller {
|
|||
return await deleteFile(fileLocation.employee.inCountryNotice(employeeId, noticeId));
|
||||
}
|
||||
}
|
||||
|
||||
@Route("api/v1/employee-export")
|
||||
@Tags("Employee")
|
||||
export class EmployeeExportController extends EmployeeController {
|
||||
@Get()
|
||||
@Security("keycloak")
|
||||
async exportEmployee(
|
||||
@Request() req: RequestWithUser,
|
||||
@Query() zipCode?: string,
|
||||
@Query() gender?: string,
|
||||
@Query() status?: Status,
|
||||
@Query() visa?: boolean,
|
||||
@Query() passport?: boolean,
|
||||
@Query() customerId?: string,
|
||||
@Query() customerBranchId?: string,
|
||||
@Query() query: string = "",
|
||||
@Query() page: number = 1,
|
||||
@Query() pageSize: number = 30,
|
||||
@Query() activeOnly?: boolean,
|
||||
@Query() startDate?: Date,
|
||||
@Query() endDate?: Date,
|
||||
) {
|
||||
const ret = await this.listByCriteria(
|
||||
req,
|
||||
zipCode,
|
||||
gender,
|
||||
status,
|
||||
visa,
|
||||
passport,
|
||||
customerId,
|
||||
customerBranchId,
|
||||
query,
|
||||
page,
|
||||
pageSize,
|
||||
activeOnly,
|
||||
startDate,
|
||||
endDate,
|
||||
);
|
||||
|
||||
this.setHeader("Content-Type", "text/csv");
|
||||
|
||||
return json2csv(
|
||||
ret.result.map((v) =>
|
||||
Object.assign(v, {
|
||||
employeePassport: v.employeePassport?.at(0) ?? null,
|
||||
employeeVisa: v.employeeVisa?.at(0) ?? null,
|
||||
}),
|
||||
),
|
||||
{ useDateIso8601Format: true },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue