feat: enhance product listing with additional metrics and sorting options
This commit is contained in:
@@ -27,6 +27,10 @@ type ProductListRecord = {
|
||||
verdict: "FBA" | "FBM" | "SKIP";
|
||||
confidence: number | null;
|
||||
sellability_status: string | null;
|
||||
monthly_sold: number | null;
|
||||
seller_count: number | null;
|
||||
sales_rank: number | null;
|
||||
current_price: number | null;
|
||||
fetched_at: string;
|
||||
};
|
||||
|
||||
@@ -274,6 +278,21 @@ function getProductList(filters: URLSearchParams) {
|
||||
}
|
||||
|
||||
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
||||
const allowedSort = new Set([
|
||||
"asin",
|
||||
"verdict",
|
||||
"monthly_sold",
|
||||
"seller_count",
|
||||
"sales_rank",
|
||||
"current_price",
|
||||
"product_name",
|
||||
"fetched_at",
|
||||
]);
|
||||
const orderBy = parseResultSort(
|
||||
filters.get("sort"),
|
||||
allowedSort,
|
||||
"CAST(COALESCE(monthly_sold, 0) AS INTEGER) DESC, fetched_at DESC",
|
||||
);
|
||||
|
||||
const baseUnion = `
|
||||
SELECT
|
||||
@@ -286,6 +305,10 @@ function getProductList(filters: URLSearchParams) {
|
||||
verdict,
|
||||
confidence,
|
||||
sellability_status,
|
||||
monthly_sold,
|
||||
sellers AS seller_count,
|
||||
sales_rank,
|
||||
current_price,
|
||||
fetched_at
|
||||
FROM results
|
||||
UNION ALL
|
||||
@@ -299,6 +322,10 @@ function getProductList(filters: URLSearchParams) {
|
||||
verdict,
|
||||
confidence,
|
||||
sellability_status,
|
||||
monthly_sold,
|
||||
seller_count,
|
||||
sales_rank,
|
||||
current_price,
|
||||
fetched_at
|
||||
FROM product_analysis_results
|
||||
`;
|
||||
@@ -308,7 +335,7 @@ function getProductList(filters: URLSearchParams) {
|
||||
.get(...params) as { total: number };
|
||||
|
||||
const items = db
|
||||
.query(`SELECT * FROM (${baseUnion}) all_products ${where} ORDER BY fetched_at DESC LIMIT ? OFFSET ?`)
|
||||
.query(`SELECT * FROM (${baseUnion}) all_products ${where} ORDER BY ${orderBy} LIMIT ? OFFSET ?`)
|
||||
.all(...params, pageSize, offset) as ProductListRecord[];
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user