Add public category lookup options, allowlisted sort ordering, URL-backed catalog controls, and strict search route validation with regression tests.
This commit is contained in:
@@ -23,6 +23,7 @@ export function createSearchQuery({
|
||||
page = 1,
|
||||
limit = 20,
|
||||
includeSold = false,
|
||||
sort = 'recent',
|
||||
}) {
|
||||
const text = normalizeSearchQuery(query);
|
||||
|
||||
@@ -50,6 +51,10 @@ export function createSearchQuery({
|
||||
throw new Error('minPriceMinor must be <= maxPriceMinor');
|
||||
}
|
||||
|
||||
if (!['recent', 'price_low', 'price_high'].includes(sort)) {
|
||||
throw new Error('sort must be recent, price_low, or price_high');
|
||||
}
|
||||
|
||||
return {
|
||||
text,
|
||||
...(typeof category === 'string' && category.trim().length > 0 ? { category: category.trim() } : {}),
|
||||
@@ -58,6 +63,7 @@ export function createSearchQuery({
|
||||
page,
|
||||
limit,
|
||||
includeSold,
|
||||
...(sort !== 'recent' ? { sort } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user