feat: export product
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 3s
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 3s
This commit is contained in:
parent
f50285161b
commit
be3c6405c6
1 changed files with 41 additions and 0 deletions
|
|
@ -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 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue