feat: expand catalog sorting
Quality / test (push) Canceled after 0s

This commit is contained in:
2026-09-10 02:39:42 -04:00
parent 0008af9f2c
commit b036092775
8 changed files with 67 additions and 11 deletions
@@ -135,7 +135,13 @@ export function createListingRepository(db) {
const offset = (page - 1) * limit;
const sortOrder =
sort === "price_low"
sort === "updated"
? desc(listings.updatedAt)
: sort === "name_asc"
? products.name
: sort === "name_desc"
? desc(products.name)
: sort === "price_low"
? listings.askingPriceMinor
: sort === "price_high"
? desc(listings.askingPriceMinor)
@@ -58,8 +58,8 @@ 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");
if (!["recent", "updated", "name_asc", "name_desc", "price_low", "price_high"].includes(sort)) {
throw new Error("sort must be recent, updated, name_asc, name_desc, price_low, or price_high");
}
return {
@@ -57,6 +57,9 @@ test("builds a public query filter set that hides sold items by default", () =>
test("accepts only the supported public search sort values", () => {
assert.equal(createSearchQuery({ sort: "price_low" }).sort, "price_low");
assert.equal(createSearchQuery({ sort: "updated" }).sort, "updated");
assert.equal(createSearchQuery({ sort: "name_asc" }).sort, "name_asc");
assert.equal(createSearchQuery({ sort: "name_desc" }).sort, "name_desc");
assert.throws(
() => createSearchQuery({ sort: "random" }),
/sort must be recent/,