feat: add advanced filtering options for Stalker products including price, sales rank, and seller metrics
This commit is contained in:
@@ -829,6 +829,20 @@ function parseStalkerProductFilters(filters: URLSearchParams) {
|
||||
const q = filters.get("q")?.trim() || "";
|
||||
const sellerId = filters.get("sellerId")?.trim().toUpperCase() || "";
|
||||
const runIdRaw = filters.get("runId")?.trim() || "";
|
||||
const verdict = filters.get("verdict")?.trim().toUpperCase() || "";
|
||||
const amazonIsSeller = filters.get("amazonIsSeller")?.trim() || "";
|
||||
const minPriceRaw = filters.get("minPrice")?.trim() || "";
|
||||
const maxPriceRaw = filters.get("maxPrice")?.trim() || "";
|
||||
const minMonthlySoldRaw = filters.get("minMonthlySold")?.trim() || "";
|
||||
const maxMonthlySoldRaw = filters.get("maxMonthlySold")?.trim() || "";
|
||||
const minSalesRankRaw = filters.get("minSalesRank")?.trim() || "";
|
||||
const maxSalesRankRaw = filters.get("maxSalesRank")?.trim() || "";
|
||||
const minSellerCountRaw = filters.get("minSellerCount")?.trim() || "";
|
||||
const maxSellerCountRaw = filters.get("maxSellerCount")?.trim() || "";
|
||||
const minRatingCountRaw = filters.get("minRatingCount")?.trim() || "";
|
||||
const maxRatingCountRaw = filters.get("maxRatingCount")?.trim() || "";
|
||||
const minConfidenceRaw = filters.get("minConfidence")?.trim() || "";
|
||||
const maxConfidenceRaw = filters.get("maxConfidence")?.trim() || "";
|
||||
|
||||
const conditions = [
|
||||
"inv.can_sell = 1",
|
||||
@@ -849,6 +863,45 @@ function parseStalkerProductFilters(filters: URLSearchParams) {
|
||||
params.push(sellerId);
|
||||
}
|
||||
|
||||
if (verdict === "FBA" || verdict === "FBM" || verdict === "SKIP") {
|
||||
conditions.push("analysis.verdict = ?");
|
||||
params.push(verdict);
|
||||
} else if (verdict === "UNANALYZED") {
|
||||
conditions.push("analysis.verdict IS NULL");
|
||||
}
|
||||
|
||||
if (amazonIsSeller === "yes") {
|
||||
conditions.push("inv.amazon_is_seller = 1");
|
||||
} else if (amazonIsSeller === "no") {
|
||||
conditions.push("inv.amazon_is_seller = 0");
|
||||
} else if (amazonIsSeller === "unknown") {
|
||||
conditions.push("inv.amazon_is_seller IS NULL");
|
||||
}
|
||||
|
||||
const numericFilters: Array<[string, string, string]> = [
|
||||
[minPriceRaw, "inv.current_price >= ?", "minPrice"],
|
||||
[maxPriceRaw, "inv.current_price <= ?", "maxPrice"],
|
||||
[minMonthlySoldRaw, "inv.monthly_sold >= ?", "minMonthlySold"],
|
||||
[maxMonthlySoldRaw, "inv.monthly_sold <= ?", "maxMonthlySold"],
|
||||
[minSalesRankRaw, "inv.sales_rank >= ?", "minSalesRank"],
|
||||
[maxSalesRankRaw, "inv.sales_rank <= ?", "maxSalesRank"],
|
||||
[minSellerCountRaw, "inv.seller_count >= ?", "minSellerCount"],
|
||||
[maxSellerCountRaw, "inv.seller_count <= ?", "maxSellerCount"],
|
||||
[minRatingCountRaw, "s.rating_count >= ?", "minRatingCount"],
|
||||
[maxRatingCountRaw, "s.rating_count <= ?", "maxRatingCount"],
|
||||
[minConfidenceRaw, "analysis.confidence >= ?", "minConfidence"],
|
||||
[maxConfidenceRaw, "analysis.confidence <= ?", "maxConfidence"],
|
||||
];
|
||||
|
||||
for (const [raw, condition] of numericFilters) {
|
||||
if (!raw) continue;
|
||||
const value = Number(raw);
|
||||
if (Number.isFinite(value)) {
|
||||
conditions.push(condition);
|
||||
params.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
if (q) {
|
||||
const wildcard = `%${q}%`;
|
||||
conditions.push(
|
||||
|
||||
Reference in New Issue
Block a user