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);
// Use RPC to bypass RLS on order_groups update
const { data: rpcData, error: rpcError } = await client.rpc("assign_driver", {
p_order_group_id: orderGroupId,
p_driver_id: driverId || null,
});
// Direct UPDATE — RLS allows manager/logistician/admin
const { error: updateError } = await client
.from("order_groups")
.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 (rpcError) {
throw rpcError;
}
if (!rpcData) {
throw new Error("Группа не найдена");
if (updateError) {
throw updateError;
}
// Fetch with driver join for the mapper