mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-27 06:05:19 +00:00
Creating and then updating the new override updates the same override instead of creating a duplicate
This commit is contained in:
@@ -44,8 +44,9 @@ angular.module("ofn.admin").controller "AdminVariantOverridesCtrl", ($scope, $ti
|
||||
else
|
||||
StatusMessage.display 'progress', 'Saving...'
|
||||
DirtyVariantOverrides.save()
|
||||
.success (data) ->
|
||||
.success (updatedVos) ->
|
||||
DirtyVariantOverrides.clear()
|
||||
VariantOverrides.updateIds updatedVos
|
||||
$timeout -> StatusMessage.display 'success', 'Changes saved.'
|
||||
.error (data, status) ->
|
||||
$timeout -> StatusMessage.display 'failure', $scope.updateError(data, status)
|
||||
|
||||
@@ -17,3 +17,7 @@ angular.module("ofn.admin").factory "VariantOverrides", (variantOverrides, Index
|
||||
hub_id: hub.id
|
||||
price: ''
|
||||
count_on_hand: ''
|
||||
|
||||
updateIds: (updatedVos) ->
|
||||
for vo in updatedVos
|
||||
@variantOverrides[vo.hub_id][vo.variant_id].id = vo.id
|
||||
@@ -23,7 +23,8 @@ module Admin
|
||||
vo_set.collection.each { |vo| authorize! :update, vo }
|
||||
|
||||
if vo_set.save
|
||||
render json: {}
|
||||
# Return saved VOs with IDs
|
||||
render json: vo_set.collection, each_serializer: Api::Admin::VariantOverrideSerializer
|
||||
else
|
||||
if vo_set.errors.present?
|
||||
render json: { errors: vo_set.errors }, status: 400
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
class Api::Admin::VariantOverrideSerializer < ActiveModel::Serializer
|
||||
attributes :id, :variant_id, :hub_id, :price, :count_on_hand
|
||||
attributes :id, :hub_id, :variant_id, :price, :count_on_hand
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user