feat: assign orders to companies directly and support admin reassignment
All checks were successful
Staging Build / build (push) Successful in 3m36s
All checks were successful
Staging Build / build (push) Successful in 3m36s
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user