@@ -75,6 +75,9 @@ export function createListingRepository(db) {
|
||||
text = "",
|
||||
category,
|
||||
conditionId,
|
||||
setName,
|
||||
eventName,
|
||||
tag,
|
||||
minPriceMinor,
|
||||
maxPriceMinor,
|
||||
page = 1,
|
||||
@@ -104,6 +107,18 @@ export function createListingRepository(db) {
|
||||
conditions.push(eq(inventoryItems.conditionId, conditionId));
|
||||
}
|
||||
|
||||
if (typeof setName === "string" && setName.trim().length > 0) {
|
||||
conditions.push(ilike(products.setName, setName));
|
||||
}
|
||||
|
||||
if (typeof eventName === "string" && eventName.trim().length > 0) {
|
||||
conditions.push(ilike(products.eventName, eventName));
|
||||
}
|
||||
|
||||
if (typeof tag === "string" && tag.trim().length > 0) {
|
||||
conditions.push(sql`${products.tags}::text ILIKE ${`%${tag}%`}`);
|
||||
}
|
||||
|
||||
if (typeof minPriceMinor === "number") {
|
||||
conditions.push(sql`listings.asking_price_minor >= ${minPriceMinor}`);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,9 @@ export function createSearchQuery({
|
||||
query = "",
|
||||
category,
|
||||
conditionId,
|
||||
setName,
|
||||
eventName,
|
||||
tag,
|
||||
minPriceMinor,
|
||||
maxPriceMinor,
|
||||
page = 1,
|
||||
@@ -70,6 +73,15 @@ export function createSearchQuery({
|
||||
...(typeof conditionId === "string" && conditionId.trim().length > 0
|
||||
? { conditionId: conditionId.trim() }
|
||||
: {}),
|
||||
...(typeof setName === "string" && setName.trim().length > 0
|
||||
? { setName: setName.trim() }
|
||||
: {}),
|
||||
...(typeof eventName === "string" && eventName.trim().length > 0
|
||||
? { eventName: eventName.trim() }
|
||||
: {}),
|
||||
...(typeof tag === "string" && tag.trim().length > 0
|
||||
? { tag: tag.trim().toLowerCase() }
|
||||
: {}),
|
||||
...(typeof minPriceMinor === "number" ? { minPriceMinor } : {}),
|
||||
...(typeof maxPriceMinor === "number" ? { maxPriceMinor } : {}),
|
||||
page,
|
||||
|
||||
@@ -32,6 +32,9 @@ export async function registerPublicSearchRoutes(app, options) {
|
||||
query: request.query.query,
|
||||
category: request.query.category,
|
||||
conditionId: request.query.conditionId,
|
||||
setName: request.query.setName,
|
||||
eventName: request.query.eventName,
|
||||
tag: request.query.tag,
|
||||
minPriceMinor: coerceNumber(
|
||||
request.query.minPriceMinor,
|
||||
"minPriceMinor",
|
||||
|
||||
@@ -11,6 +11,9 @@ test("normalizes a public search query and keeps filter values within bounds", (
|
||||
const query = createSearchQuery({
|
||||
query: " Charizard ex ",
|
||||
category: "Cards",
|
||||
setName: "SV151",
|
||||
eventName: "Worlds",
|
||||
tag: "Binder",
|
||||
minPriceMinor: 1000,
|
||||
maxPriceMinor: 5000,
|
||||
page: 1,
|
||||
@@ -20,6 +23,9 @@ test("normalizes a public search query and keeps filter values within bounds", (
|
||||
|
||||
assert.equal(query.text, "charizard ex");
|
||||
assert.equal(query.category, "Cards");
|
||||
assert.equal(query.setName, "SV151");
|
||||
assert.equal(query.eventName, "Worlds");
|
||||
assert.equal(query.tag, "binder");
|
||||
assert.equal(query.minPriceMinor, 1000);
|
||||
assert.equal(query.maxPriceMinor, 5000);
|
||||
assert.equal(query.page, 1);
|
||||
|
||||
@@ -12,6 +12,9 @@ test("returns public search results with pagination metadata", async (testContex
|
||||
assert.equal(filters.includeSold, true);
|
||||
assert.equal(filters.sort, "price_low");
|
||||
assert.equal(filters.conditionId, "condition-1");
|
||||
assert.equal(filters.setName, "SV151");
|
||||
assert.equal(filters.eventName, "Worlds");
|
||||
assert.equal(filters.tag, "binder");
|
||||
return {
|
||||
items: [{ id: "listing-1", status: "CLOSED" }],
|
||||
pagination: { page: 2, limit: 5, total: 6, totalPages: 2 },
|
||||
@@ -23,7 +26,7 @@ test("returns public search results with pagination metadata", async (testContex
|
||||
|
||||
const response = await app.inject({
|
||||
method: "GET",
|
||||
url: "/api/v1/public/search?query=charizard&page=2&limit=5&includeSold=true&sort=price_low&conditionId=condition-1",
|
||||
url: "/api/v1/public/search?query=charizard&page=2&limit=5&includeSold=true&sort=price_low&conditionId=condition-1&setName=SV151&eventName=Worlds&tag=binder",
|
||||
});
|
||||
|
||||
assert.equal(response.statusCode, 200);
|
||||
|
||||
Reference in New Issue
Block a user