fix: replace assign_driver RPC with direct supabase update

This commit is contained in:
root 2026-05-26 19:55:35 +00:00
parent 41e36299b7
commit f451add13c
1 changed files with 11 additions and 12 deletions

View File

@ -221,19 +221,18 @@ export const assignDriverToOrderGroup = async ({
logger.debug("[assignDriver] orderGroupId:", orderGroupId, "driverId:", driverId); logger.debug("[assignDriver] orderGroupId:", orderGroupId, "driverId:", driverId);
// Use RPC to bypass RLS on order_groups update // Direct UPDATE — RLS allows manager/logistician/admin
const { data: rpcData, error: rpcError } = await client.rpc("assign_driver", { const { error: updateError } = await client
p_order_group_id: orderGroupId, .from("order_groups")
p_driver_id: driverId || null, .update({
}); assigned_driver_id: driverId || null,
delivery_status: driverId ? "driver_assigned" : undefined,
updated_at: new Date().toISOString(),
})
.eq("id", orderGroupId);
logger.debug("[assignDriver] rpc result:", { rpcData, rpcError }); if (updateError) {
if (rpcError) { throw updateError;
throw rpcError;
}
if (!rpcData) {
throw new Error("Группа не найдена");
} }
// Fetch with driver join for the mapper // Fetch with driver join for the mapper