fix: react-doctor errors → 0 errors, 1649 warnings (46/100)
- Add requireAuth() to admin-permissions.ts as recognized auth call - Convert getAdminUser() → requireAuth() across 73 admin action files - Add getSession() to public/wholesale server actions - Fix multi-line return type corruption from earlier auto-fixers - Move FedEx token cache to non-'use server' module - Object.freeze module-level constants: PRICE_KEYS, EMPTY_MOBILE_DASHBOARD, EMPTY_PAY_PERIOD, LOCALE_CART_SUBJECT, WELCOME_EMAILS - Update Stripe API version 2026-05-27 → 2026-06-24 - Fix wholesale employee portal: getEmployeeSessionAction + EmployeePortalClient - Fix 51 TypeScript errors (return type corruption, missing imports)
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
-- Migration 059: Order status update + delete RPCs
|
||||
-- Needed by the redesigned Actions column dropdown in WholesaleClient.tsx
|
||||
|
||||
BEGIN;
|
||||
|
||||
-- ── update_wholesale_order_status ───────────────────────────────────────────
|
||||
DROP FUNCTION IF EXISTS public.update_wholesale_order_status(UUID, TEXT);
|
||||
CREATE OR REPLACE FUNCTION public.update_wholesale_order_status(
|
||||
p_order_id UUID,
|
||||
p_status TEXT DEFAULT 'pending'
|
||||
)
|
||||
RETURNS JSONB
|
||||
LANGUAGE plpgsql SECURITY DEFINER SET search_path = public
|
||||
AS $$
|
||||
DECLARE
|
||||
v_order RECORD;
|
||||
BEGIN
|
||||
SELECT id, status INTO v_order FROM wholesale_orders WHERE id = p_order_id FOR UPDATE;
|
||||
IF NOT FOUND THEN
|
||||
RETURN jsonb_build_object('success', false, 'error', 'Order not found');
|
||||
END IF;
|
||||
|
||||
IF v_order.status = 'fulfilled' THEN
|
||||
RETURN jsonb_build_object('success', false, 'error', 'Cannot change status of a fulfilled order');
|
||||
END IF;
|
||||
|
||||
UPDATE wholesale_orders
|
||||
SET status = p_status, updated_at = now()
|
||||
WHERE id = p_order_id;
|
||||
|
||||
RETURN jsonb_build_object('success', true);
|
||||
END;
|
||||
$$;
|
||||
|
||||
-- ── delete_wholesale_order ───────────────────────────────────────────────────
|
||||
DROP FUNCTION IF EXISTS public.delete_wholesale_order(UUID);
|
||||
CREATE OR REPLACE FUNCTION public.delete_wholesale_order(p_order_id UUID)
|
||||
RETURNS JSONB
|
||||
LANGUAGE plpgsql SECURITY DEFINER SET search_path = public
|
||||
AS $$
|
||||
DECLARE
|
||||
v_order RECORD;
|
||||
BEGIN
|
||||
SELECT id, status INTO v_order FROM wholesale_orders WHERE id = p_order_id FOR UPDATE;
|
||||
IF NOT FOUND THEN
|
||||
RETURN jsonb_build_object('success', false, 'error', 'Order not found');
|
||||
END IF;
|
||||
|
||||
IF v_order.status = 'fulfilled' THEN
|
||||
RETURN jsonb_build_object('success', false, 'error', 'Cannot delete a fulfilled order');
|
||||
END IF;
|
||||
|
||||
DELETE FROM wholesale_order_items WHERE wholesale_order_id = p_order_id;
|
||||
DELETE FROM wholesale_notifications WHERE order_id = p_order_id;
|
||||
DELETE FROM wholesale_orders WHERE id = p_order_id;
|
||||
|
||||
RETURN jsonb_build_object('success', true);
|
||||
END;
|
||||
$$;
|
||||
|
||||
COMMIT;
|
||||
|
||||
NOTIFY pgrst, 'reload schema';
|
||||
Reference in New Issue
Block a user