Add public condition lookup options, condition filtering, and stable price/recent sorting with URL-backed catalog controls.
This commit is contained in:
@@ -4,4 +4,8 @@ export async function registerPublicLookupRoutes(app, options) {
|
||||
app.get('/public/lookups/categories', async () => ({
|
||||
data: await catalogLookupRepository.listCategories(),
|
||||
}));
|
||||
|
||||
app.get('/public/lookups/conditions', async () => ({
|
||||
data: (await catalogLookupRepository.listConditions()).map(({ id, name, code }) => ({ id, name, code })),
|
||||
}));
|
||||
}
|
||||
@@ -48,6 +48,7 @@ export function createListingRepository(db) {
|
||||
const {
|
||||
text = '',
|
||||
category,
|
||||
conditionId,
|
||||
minPriceMinor,
|
||||
maxPriceMinor,
|
||||
page = 1,
|
||||
@@ -68,6 +69,10 @@ export function createListingRepository(db) {
|
||||
conditions.push(eq(products.categoryId, category));
|
||||
}
|
||||
|
||||
if (typeof conditionId === 'string' && conditionId.trim().length > 0) {
|
||||
conditions.push(eq(inventoryItems.conditionId, conditionId));
|
||||
}
|
||||
|
||||
if (typeof minPriceMinor === 'number') {
|
||||
conditions.push(sql`listings.asking_price_minor >= ${minPriceMinor}`);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ export function normalizeSearchQuery(value) {
|
||||
export function createSearchQuery({
|
||||
query = '',
|
||||
category,
|
||||
conditionId,
|
||||
minPriceMinor,
|
||||
maxPriceMinor,
|
||||
page = 1,
|
||||
@@ -58,6 +59,7 @@ export function createSearchQuery({
|
||||
return {
|
||||
text,
|
||||
...(typeof category === 'string' && category.trim().length > 0 ? { category: category.trim() } : {}),
|
||||
...(typeof conditionId === 'string' && conditionId.trim().length > 0 ? { conditionId: conditionId.trim() } : {}),
|
||||
...(typeof minPriceMinor === 'number' ? { minPriceMinor } : {}),
|
||||
...(typeof maxPriceMinor === 'number' ? { maxPriceMinor } : {}),
|
||||
page,
|
||||
|
||||
@@ -27,6 +27,7 @@ export async function registerPublicSearchRoutes(app, options) {
|
||||
const filters = {
|
||||
query: request.query.query,
|
||||
category: request.query.category,
|
||||
conditionId: request.query.conditionId,
|
||||
minPriceMinor: coerceNumber(request.query.minPriceMinor, 'minPriceMinor', undefined),
|
||||
maxPriceMinor: coerceNumber(request.query.maxPriceMinor, 'maxPriceMinor', undefined),
|
||||
page: coerceNumber(request.query.page, 'page', 1),
|
||||
|
||||
@@ -11,6 +11,7 @@ test('returns public search results with pagination metadata', async (testContex
|
||||
assert.equal(filters.limit, 5);
|
||||
assert.equal(filters.includeSold, true);
|
||||
assert.equal(filters.sort, 'price_low');
|
||||
assert.equal(filters.conditionId, 'condition-1');
|
||||
return {
|
||||
items: [{ id: 'listing-1', status: 'CLOSED' }],
|
||||
pagination: { page: 2, limit: 5, total: 6, totalPages: 2 },
|
||||
@@ -22,7 +23,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',
|
||||
url: '/api/v1/public/search?query=charizard&page=2&limit=5&includeSold=true&sort=price_low&conditionId=condition-1',
|
||||
});
|
||||
|
||||
assert.equal(response.statusCode, 200);
|
||||
@@ -59,4 +60,17 @@ test('returns active public category options', async (testContext) => {
|
||||
const response = await app.inject({ method: 'GET', url: '/api/v1/public/lookups/categories' });
|
||||
assert.equal(response.statusCode, 200);
|
||||
assert.deepEqual(response.json().data, [{ id: 'category-1', name: 'Trading Cards' }]);
|
||||
});
|
||||
|
||||
test('returns public condition options without category internals', async (testContext) => {
|
||||
const app = buildApp({
|
||||
catalogLookupRepository: {
|
||||
async listConditions() { return [{ id: 'condition-1', name: 'Near Mint', code: 'NM', categoryId: 'private-category' }]; },
|
||||
},
|
||||
});
|
||||
testContext.after(() => app.close());
|
||||
|
||||
const response = await app.inject({ method: 'GET', url: '/api/v1/public/lookups/conditions' });
|
||||
assert.equal(response.statusCode, 200);
|
||||
assert.deepEqual(response.json().data, [{ id: 'condition-1', name: 'Near Mint', code: 'NM' }]);
|
||||
});
|
||||
Reference in New Issue
Block a user