I
Например, заказ может иметь только одного водителя, и есть айдишник водителя проставляется в заказе, то, имхо, трабл быть не должно, либо лок записи решит возможную проблему
Size: a a a
I
I
ЭК
def accept
order = Order.find(params[:order][:order_id])
if order.nil?
return render json: {success: false, data: "Ошибка: заказ не найден!"}
end
if order && order.status == OPEN
unless @current_driver.balance_sufficient?(subtract_amount: order.tariff&.commission)
return render json: {success: false, data: t("models.driver.errors.balance.insufficient", balance: @current_driver.balance, currency: CURRENCY)}, status: 200
end
if @current_driver.status == FREE
if order.update_attributes(status: ACCEPTED, driver_id: @current_driver.id) && @current_driver.update_columns(status: ACCEPTED)
order.save!
render json: {success: true, tariff: Tariff.find(order.tariff_id)}, status: 200
else
order.save!
render json: {success: false, data: 'Произошла ошибка'}, status: 200
end
else
order.save!
render json: {success: false, data: "Ваш статус должен быть свободен!"}, status: 200
end
else
order.save!
title = order.status == CANCELLED ? 'Заказ был отменен!' : 'Заказ уже занят!'
render json: {success: false, data: title, order_status: order.status}, status: 200
end
end
ЭК
Т
def accept
order = Order.find(params[:order][:order_id])
if order.nil?
return render json: {success: false, data: "Ошибка: заказ не найден!"}
end
if order && order.status == OPEN
unless @current_driver.balance_sufficient?(subtract_amount: order.tariff&.commission)
return render json: {success: false, data: t("models.driver.errors.balance.insufficient", balance: @current_driver.balance, currency: CURRENCY)}, status: 200
end
if @current_driver.status == FREE
if order.update_attributes(status: ACCEPTED, driver_id: @current_driver.id) && @current_driver.update_columns(status: ACCEPTED)
order.save!
render json: {success: true, tariff: Tariff.find(order.tariff_id)}, status: 200
else
order.save!
render json: {success: false, data: 'Произошла ошибка'}, status: 200
end
else
order.save!
render json: {success: false, data: "Ваш статус должен быть свободен!"}, status: 200
end
else
order.save!
title = order.status == CANCELLED ? 'Заказ был отменен!' : 'Заказ уже занят!'
render json: {success: false, data: title, order_status: order.status}, status: 200
end
end
ЭК
I
def accept
order = Order.find(params[:order][:order_id])
if order.nil?
return render json: {success: false, data: "Ошибка: заказ не найден!"}
end
if order && order.status == OPEN
unless @current_driver.balance_sufficient?(subtract_amount: order.tariff&.commission)
return render json: {success: false, data: t("models.driver.errors.balance.insufficient", balance: @current_driver.balance, currency: CURRENCY)}, status: 200
end
if @current_driver.status == FREE
if order.update_attributes(status: ACCEPTED, driver_id: @current_driver.id) && @current_driver.update_columns(status: ACCEPTED)
order.save!
render json: {success: true, tariff: Tariff.find(order.tariff_id)}, status: 200
else
order.save!
render json: {success: false, data: 'Произошла ошибка'}, status: 200
end
else
order.save!
render json: {success: false, data: "Ваш статус должен быть свободен!"}, status: 200
end
else
order.save!
title = order.status == CANCELLED ? 'Заказ был отменен!' : 'Заказ уже занят!'
render json: {success: false, data: title, order_status: order.status}, status: 200
end
end
I
I
AI
AI
AI
AI
AI
AI
u
UPDATE … SET.. WHERE.. RETURNING
?ℹ🅿
UPDATE … SET.. WHERE.. RETURNING
?RU
UPDATE … SET.. WHERE.. RETURNING
?u
ch
def accept
order = Order.find(params[:order][:order_id])
if order.nil?
return render json: {success: false, data: "Ошибка: заказ не найден!"}
end
if order && order.status == OPEN
unless @current_driver.balance_sufficient?(subtract_amount: order.tariff&.commission)
return render json: {success: false, data: t("models.driver.errors.balance.insufficient", balance: @current_driver.balance, currency: CURRENCY)}, status: 200
end
if @current_driver.status == FREE
if order.update_attributes(status: ACCEPTED, driver_id: @current_driver.id) && @current_driver.update_columns(status: ACCEPTED)
order.save!
render json: {success: true, tariff: Tariff.find(order.tariff_id)}, status: 200
else
order.save!
render json: {success: false, data: 'Произошла ошибка'}, status: 200
end
else
order.save!
render json: {success: false, data: "Ваш статус должен быть свободен!"}, status: 200
end
else
order.save!
title = order.status == CANCELLED ? 'Заказ был отменен!' : 'Заказ уже занят!'
render json: {success: false, data: title, order_status: order.status}, status: 200
end
end