Stop not found
- {error?.message ?? "Stop not found"}
+ {id}
;
+ }
- const assignedProducts = (productStops ?? [])
- .map((ps: ProductStop) => ({
- id: ps.id,
- product_id: ps.product_id,
- products: ps.products ? {
- name: ps.products.name,
- type: ps.products.type,
- price: ps.products.price,
- image_url: ps.products.image_url,
- } : null,
- }))
- .filter(Boolean);
+ const stop: Stop = {
+ id: stopRow.id,
+ brand_id: stopRow.brand_id,
+ city: stopRow.city ?? "",
+ state: stopRow.state ?? "",
+ address: stopRow.address ?? null,
+ zip: stopRow.zip ?? null,
+ date: stopRow.date ? String(stopRow.date) : "",
+ time: stopRow.time ?? "",
+ cutoff_date: stopRow.cutoff_date ? String(stopRow.cutoff_date) : null,
+ cutoff_time: stopRow.cutoff_date ? String(stopRow.cutoff_date) : null,
+ status: stopRow.status ?? "active",
+ location: stopRow.location ?? "",
+ active: stopRow.status === "active",
+ brands: { name: stopRow.brand_name ?? "", slug: stopRow.brand_slug ?? "" },
+ };
+
+ // Fetch all products for this brand
+ const { rows: productRows } = await pool.query<{ id: string; name: string; type: string; price: number; image_url: string | null }>(
+ `SELECT id, name, type, price, image_url
+ FROM products
+ WHERE brand_id = $1 AND active = true
+ ORDER BY name`,
+ [stop.brand_id]
+ );
+
+ // Fetch product-stop assignments
+ const { rows: productStopRows } = await pool.query<{ id: string; product_id: string; name: string; type: string; price: number; image_url: string | null }>(
+ `SELECT ps.id, ps.product_id, p.name, p.type, p.price, p.image_url
+ FROM product_stops ps
+ JOIN products p ON p.id = ps.product_id
+ WHERE ps.stop_id = $1`,
+ [id]
+ );
+
+ // Fetch brands list
+ const { rows: brandRows } = await pool.query<{ id: string; name: string; slug: string }>(
+ `SELECT id, name, slug FROM brands ORDER BY name`
+ );
+
+ const allProducts = productRows.map((p) => ({
+ id: p.id,
+ name: p.name,
+ type: p.type,
+ price: Number(p.price),
+ image_url: p.image_url,
+ }));
+
+ const assignedProducts = productStopRows.map((ps) => ({
+ id: ps.id,
+ product_id: ps.product_id,
+ products: {
+ name: ps.name,
+ type: ps.type,
+ price: Number(ps.price),
+ image_url: ps.image_url,
+ },
+ }));
return (
Cutoff
- {new Date(stop.cutoff_time).toLocaleString()} + {new Date(stop.cutoff_date + "T00:00:00").toLocaleDateString()}