feat: assign orders to companies directly and support admin reassignment
All checks were successful
Staging Build / build (push) Successful in 3m36s

This commit is contained in:
DanielS
2026-07-04 16:08:31 +02:00
parent 72852a6b08
commit 305af64fd6
7 changed files with 99 additions and 18 deletions

View File

@@ -193,6 +193,7 @@ export async function submitOrder(params: {
.from('orders')
.insert([{
user_id: user.id,
company_id: dbUser?.company_id || null,
order_number: orderNumber,
order_hash: orderHash,
end_customer_id: endCustomerId ?? null,
@@ -481,9 +482,10 @@ export async function updateOrder(
endCustomer?: EndCustomer | null
billingInterval?: 'one_time' | 'monthly'
lastLicenseDate?: string | null
companyId?: string | null
}
): Promise<Order> {
const { selections, moduleQuantities, customerProfile, endCustomerId, endCustomer, billingInterval, lastLicenseDate } = params
const { selections, moduleQuantities, customerProfile, endCustomerId, endCustomer, billingInterval, lastLicenseDate, companyId } = params
const supabase = await createClient()
const admin = createAdminClient()
@@ -612,15 +614,21 @@ export async function updateOrder(
const orderHash = hashOrderSnapshot(orderSnapshot)
// 2. Bestellung in DB aktualisieren
const updatePayload: any = {
end_customer_id: endCustomerId ?? null,
total_price: orderSnapshot.total,
customer_data: customerSnapshot,
order_data: orderSnapshot,
order_hash: orderHash,
}
if (isAdmin && companyId !== undefined) {
updatePayload.company_id = companyId
}
const { data: order, error: orderError } = await admin
.from('orders')
.update({
end_customer_id: endCustomerId ?? null,
total_price: orderSnapshot.total,
customer_data: customerSnapshot,
order_data: orderSnapshot,
order_hash: orderHash,
})
.update(updatePayload)
.eq('id', orderId)
.select()
.single()