migrate: replace Supabase REST with Drizzle/pg in 28 more files (wave 5 final)

- admin components: TaxDashboard, OrderTableBody, TaxQuarterlySummary, StopProductAssignment, StopTableClient, ProductAssignmentForm, StopMessagingForm
- api routes: wholesale/checkout, wholesale/price-sheet, api/supabase (DELETED), api/reports/export, route-trace/* (stubbed - feature retired)
- lib: src/lib/supabase.ts (mock-only shim, no @supabase imports), src/lib/supabase/server.ts (DELETED)
- actions: wholesale-auth (stubbed - awaiting Auth.js migration), shipping/settings, water-log/*, tax (added getTaxSummaryAction/getTaxableOrdersAction), time-tracking/* (stubbed)
- new actions: stops/manage-stop-products (assign/unassign), stops/get-stop-customers (pending pickup list), orders.toggleOrderPickupComplete (legacy column)

All Supabase REST calls replaced with Drizzle ORM, raw pg.Pool queries, or
existing server actions. Typecheck: clean. Tests: 22/22 pass. Build: OK.
This commit is contained in:
2026-06-07 06:24:57 +00:00
parent 67abcaa2db
commit 50201b00fe
31 changed files with 1589 additions and 2866 deletions
+34
View File
@@ -226,3 +226,37 @@ export async function getAdminOrderDetail(orderId: string): Promise<AdminOrderDe
return null;
}
}
/**
* Toggle the `pickup_complete` flag on the legacy `orders` table.
* TODO(migration): the SaaS rebuild's `orders` table (db/schema/orders.ts)
* doesn't carry a `pickup_complete` column. This action writes to the
* legacy column so the OrderTableBody client component keeps working.
* When the pickup flow is rebuilt against the SaaS schema, this should
* be replaced by a Drizzle update on a `pickup_events` table.
*/
export async function toggleOrderPickupComplete(params: {
orderId: string;
pickupComplete: boolean;
}): Promise<{ success: true } | { success: false; error: string }> {
const adminUser = await getAdminUser();
if (!adminUser) return { success: false, error: "Not authenticated" };
if (!adminUser.can_manage_orders) return { success: false, error: "Not authorized" };
try {
await pool.query(
`UPDATE orders
SET pickup_complete = $2,
pickup_completed_at = CASE WHEN $2 THEN NOW() ELSE NULL END,
pickup_completed_by = CASE WHEN $2 THEN $3::uuid ELSE NULL END
WHERE id = $1`,
[params.orderId, params.pickupComplete, adminUser.user_id],
);
return { success: true };
} catch (err) {
return {
success: false,
error: err instanceof Error ? err.message : "Failed to update pickup status",
};
}
}