feat(dashboard): add customer accordion view and extension flow
All checks were successful
Staging Build / build (push) Successful in 3m1s
All checks were successful
Staging Build / build (push) Successful in 3m1s
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
'use server'
|
||||
|
||||
import { createClient } from '@/lib/supabase/server'
|
||||
import type { Order, EndCustomer } from '@/lib/types'
|
||||
import type { Order, EndCustomer, EndCustomerWithOrders, OrderWithRegisterName } from '@/lib/types'
|
||||
|
||||
/**
|
||||
* Holt alle Bestellanfragen.
|
||||
@@ -34,3 +34,42 @@ export async function getCompanyEndCustomers(): Promise<EndCustomer[]> {
|
||||
if (error) throw error
|
||||
return data as EndCustomer[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt alle Endkunden inkl. ihrer Bestellungen/Kassen verschachtelt.
|
||||
* Extrahiert den Kassen-Namen aus order_data.items[0].device_name (Fallback "Kasse 1").
|
||||
* RLS filtert automatisch über get_auth_company_id().
|
||||
*/
|
||||
export async function getPartnerCustomersWithOrders(): Promise<EndCustomerWithOrders[]> {
|
||||
const supabase = await createClient()
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('end_customers')
|
||||
.select('*, orders(*)')
|
||||
.order('company_name', { ascending: true })
|
||||
|
||||
if (error) throw error
|
||||
|
||||
return (data || []).map((customer: any) => {
|
||||
const rawOrders = customer.orders || []
|
||||
// Sort orders by created_at desc
|
||||
const sortedOrders = [...rawOrders].sort(
|
||||
(a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()
|
||||
)
|
||||
|
||||
const orders: OrderWithRegisterName[] = sortedOrders.map((order: any) => {
|
||||
const items = order.order_data?.items || []
|
||||
const deviceName = items[0]?.device_name || 'Kasse 1'
|
||||
return {
|
||||
...order,
|
||||
register_name: deviceName,
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
...customer,
|
||||
orders,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -170,6 +170,14 @@ export type Order = {
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export type OrderWithRegisterName = Order & {
|
||||
register_name: string
|
||||
}
|
||||
|
||||
export type EndCustomerWithOrders = EndCustomer & {
|
||||
orders: OrderWithRegisterName[]
|
||||
}
|
||||
|
||||
// ─── Lizenz-Output (für Lizenzserver / ERP) ───────────────────────────────────
|
||||
|
||||
export type LicenseOption = {
|
||||
|
||||
Reference in New Issue
Block a user