src/services/admin/. Each file is a named module exporting async functions that call Supabase with explicit column selectors. All admin operations require the user to pass checkIsAdmin() — enforced by the AdminGuard component at the route level.
Auth
checkIsAdmin()
admin_users table. Returns false on any error, never throws.
Dashboard
Functions inadmin-dashboard.service.ts.
getPulseMetrics()
getDashboardStats()
getRecentOrders()
customer_profiles and addresses tables.
getDashboardPulse()
dashboard-intelligence edge function with current stats. Returns an AI-generated executive narrative, anomaly list, and 0–100 health score.
searchCommandPalette()
Products
Functions inadmin-products.service.ts.
| Function | Signature | Description |
|---|---|---|
getAllProducts() | (): Promise<ProductRow[]> | All products ordered by created_at DESC, including specs, badges, AI fields |
getProductById(id) | (id: string): Promise<ProductRow> | Single product with full variant tree |
createProduct(product) | (product: ProductFormData): Promise<...> | Inserts and returns id, name, slug, price, stock, sku, section, category_id, is_active |
updateProduct(id, product) | (id: string, data: Partial<ProductFormData>): Promise<...> | Partial update |
deleteProduct(id) | (id: string): Promise<void> | Soft delete — sets is_active = false |
toggleProductFlag(id, flag, value) | (id: string, flag: 'is_featured'|'is_new'|'is_bestseller'|'is_active', value: boolean) | Toggles a single boolean flag |
uploadProductImage(file) | (file: File): Promise<string> | Uploads to product-images Storage bucket, returns public URL |
bulkUpdateProducts(updates) | (updates: { id: string; updates: Partial<ProductFormData> }[]): Promise<...> | Batch update via Promise.all |
generateProductCopy(name, desc?) | (name: string, desc?: string): Promise<{ description, short_description, tags }> | AI copy generation via product-intelligence edge function |
ProductFormData
Categories
Functions inadmin-categories.service.ts.
| Function | Description |
|---|---|
getAllCategories() | All categories ordered by section, then order_index |
createCategory(data) | Insert new category |
updateCategory(id, data) | Partial update |
deleteCategory(id) | Hard delete — a DB trigger re-parents children and moves orphaned products |
toggleCategoryActive(id, flag) | Toggle is_active |
Orders
Functions inadmin-orders.service.ts.
| Function | Description |
|---|---|
getAllOrders(statusFilter?) | All orders with joined customer name/phone. Optional status filter. |
updateOrderStatus(orderId, status) | Updates status; auto-sets payment_status = 'paid' for processing, shipped, delivered |
updateOrderPaymentStatus(orderId, paymentStatus) | Manual payment status override |
updateOrderTracking(orderId, trackingNumber) | Sets tracking_notes field |
exportOrdersToCSV(orders) | Client-side CSV download with UTF-8 BOM |
OrderStatus values
Customers
Functions inadmin-customers.service.ts. Reads from the customer_intelligence_360 view for enriched CRM data.
| Function | Description |
|---|---|
getAllCustomers() | All customers from customer_intelligence_360 view with RFM segment and health status |
getAdminCustomerDetails(id) | Full customer detail: profile + orders summary + addresses + admin notes + evidence files |
getCustomerOrders(id) | Order history for a specific customer |
getCustomerPreferences(id) | Top 5 products and categories by purchase volume |
createCustomerWithDetails(data) | Creates Auth user + profile + address via a temp Supabase client (preserves admin session) |
updateAdminCustomerNotes(id, data) | Upsert CRM notes, tags, custom fields |
uploadCustomerEvidence(id, file) | Upload file to customer-evidence Storage bucket |
updateCustomerStatus(id, status, end?) | God Mode: set active, suspended, or banned |
sendCustomerNotification(id, title, msg, type) | Insert into user_notifications table |
getCustomerWishlist(id) | Wishlist items with joined product data |
suggestCustomerTags(id) | AI tag suggestions via customer-intelligence edge function |
Coupons
Functions inadmin-coupons.service.ts.
| Function | Description |
|---|---|
getAllCoupons() | All coupons ordered by code |
createCoupon(data) | Insert new coupon with used_count = 0 |
updateCoupon(code, data) | Partial update by coupon code |
deleteCoupon(code) | Soft delete — sets is_active = false |
generateCouponMagic(goal) | AI-generated coupon suggestion via marketing-intelligence edge function |
forecastCouponImpact(coupon) | AI impact analysis via marketing-intelligence edge function |
AdminCoupon
Storage
Product image upload lives inadmin-products.service.ts:
product-images bucket under the raw/ prefix with a timestamp-randomized filename. Returns the public URL via getPublicUrl().
Customer evidence upload is in admin-customers.service.ts:
customer-evidence bucket under {customerId}/ prefix.