From 6c6792eba549993df1c947530ac906a1af8a47ca Mon Sep 17 00:00:00 2001 From: gavin-openops Date: Sun, 1 Mar 2026 20:56:05 +0000 Subject: [PATCH] feat: add is_extended_promotional filter to component search --- routes/api/search.tsx | 7 +++++++ routes/components/list.tsx | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/routes/api/search.tsx b/routes/api/search.tsx index 9d5d6a3..1f0a147 100644 --- a/routes/api/search.tsx +++ b/routes/api/search.tsx @@ -26,6 +26,7 @@ export default withWinterSpec({ limit: z.string().optional(), is_basic: z.boolean().optional(), is_preferred: z.boolean().optional(), + is_extended_promotional: z.boolean().optional(), }), jsonResponse: z.any(), } as const)(async (req, ctx) => { @@ -48,6 +49,11 @@ export default withWinterSpec({ if (req.query.is_preferred) { query = query.where("preferred", "=", 1) } + if (req.query.is_extended_promotional) { + query = query.where( + sql`json_extract(extra, '$.is_extended_promotional') = 1`, + ) + } if (req.query.q) { const rawSearchTerm = req.query.q.trim() @@ -80,6 +86,7 @@ export default withWinterSpec({ package: c.package, is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: isExtendedPromotional(c.extra), description: c.description, stock: c.stock, price: extractSmallQuantityPrice(c.price), diff --git a/routes/components/list.tsx b/routes/components/list.tsx index 8d26b56..2f5e979 100644 --- a/routes/components/list.tsx +++ b/routes/components/list.tsx @@ -13,6 +13,16 @@ const extractSmallQuantityPrice = (price: string | null) => { } } +const isExtendedPromotional = (extra: string | null): boolean => { + if (!extra) return false + try { + const extraObj = JSON.parse(extra) + return Boolean(extraObj?.is_extended_promotional) + } catch { + return false + } +} + export default withWinterSpec({ auth: "none", methods: ["GET"], @@ -23,6 +33,7 @@ export default withWinterSpec({ search: z.string().optional(), is_basic: z.boolean().optional(), is_preferred: z.boolean().optional(), + is_extended_promotional: z.boolean().optional(), }), jsonResponse: z.any(), } as const)(async (req, ctx) => { @@ -39,6 +50,7 @@ export default withWinterSpec({ "price", "extra", "basic", + "preferred", ]) .limit(limit) .orderBy("stock", "desc") @@ -58,6 +70,11 @@ export default withWinterSpec({ if (req.query.is_preferred) { query = query.where("preferred", "=", 1) } + if (req.query.is_extended_promotional) { + query = query.where( + sql`json_extract(extra, '$.is_extended_promotional') = 1`, + ) + } if (req.query.search) { const search = req.query.search // TypeScript now knows this is defined within this block @@ -82,6 +99,7 @@ export default withWinterSpec({ package: c.package, is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: isExtendedPromotional(c.extra), description: c.description, stock: c.stock, price: extractSmallQuantityPrice(c.price), @@ -126,6 +144,17 @@ export default withWinterSpec({ /> +
+ +