Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/db/generated/kysely.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export interface Component {
description: string;
extra: string | null;
flag: Generated<number>;
is_extended_promotional: number | null;
joints: number;
last_on_stock: Generated<number>;
last_update: number;
Expand Down Expand Up @@ -809,6 +810,7 @@ export interface VComponent {
mfr: string | null;
package: string | null;
preferred: number | null;
is_extended_promotional: number | null;
price: string | null;
stock: number | null;
subcategory: string | null;
Expand Down
19 changes: 19 additions & 0 deletions routes/components/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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) => {
Expand All @@ -39,6 +40,8 @@ export default withWinterSpec({
"price",
"extra",
"basic",
"preferred",
"is_extended_promotional",
])
.limit(limit)
.orderBy("stock", "desc")
Expand All @@ -59,6 +62,10 @@ export default withWinterSpec({
query = query.where("preferred", "=", 1)
}

if (req.query.is_extended_promotional) {
query = query.where("is_extended_promotional", "=", 1)
}

if (req.query.search) {
const search = req.query.search // TypeScript now knows this is defined within this block
const searchPattern = `%${search}%`
Expand All @@ -82,6 +89,7 @@ export default withWinterSpec({
package: c.package,
is_basic: Boolean(c.basic),
is_preferred: Boolean(c.preferred),
is_extended_promotional: Boolean(c.is_extended_promotional),
description: c.description,
stock: c.stock,
price: extractSmallQuantityPrice(c.price),
Expand Down Expand Up @@ -126,6 +134,17 @@ export default withWinterSpec({
/>
</label>
</div>
<div>
<label>
Extended Promotional Part:
<input
type="checkbox"
name="is_extended_promotional"
value="true"
checked={req.query.is_extended_promotional}
/>
</label>
</div>
<button type="submit">Filter</button>
</form>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ test("GET /components/list with json param returns component data", async () =>
const res = await axios.get("/components/list?json=true")
expect(res.data).toHaveProperty("components")
expect(Array.isArray(res.data.components)).toBe(true)

if (res.data.components.length > 0) {
expect(res.data.components[0]).toHaveProperty("is_extended_promotional")
}
})
12 changes: 12 additions & 0 deletions tests/routes/components/list2.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { test, expect } from "bun:test"
import { getTestServer } from "tests/fixtures/get-test-server"

test("GET /components/list supports is_extended_promotional filter", async () => {
const { axios } = await getTestServer()
const res = await axios.get(
"/components/list?json=true&is_extended_promotional=true",
)

expect(res.data).toHaveProperty("components")
expect(Array.isArray(res.data.components)).toBe(true)
})