mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Add address serializer to customer serializer
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
class Api::Admin::CustomerSerializer < ActiveModel::Serializer
|
||||
attributes :id, :email, :enterprise_id, :user_id, :code, :tags, :tag_list, :name, :bill_address, :ship_address
|
||||
attributes :id, :email, :enterprise_id, :user_id, :code, :tags, :tag_list, :name
|
||||
|
||||
has_one :ship_address, serializer: Api::AddressSerializer
|
||||
has_one :bill_address, serializer: Api::AddressSerializer
|
||||
|
||||
def tag_list
|
||||
object.tag_list.join(",")
|
||||
@@ -11,12 +14,4 @@ class Api::Admin::CustomerSerializer < ActiveModel::Serializer
|
||||
tag_rule_map || { text: tag, rules: nil }
|
||||
end
|
||||
end
|
||||
|
||||
def ship_address
|
||||
object.ship_address.andand.address1
|
||||
end
|
||||
|
||||
def bill_address
|
||||
object.bill_address.andand.address1
|
||||
end
|
||||
end
|
||||
|
||||
@@ -86,8 +86,8 @@
|
||||
.tag_watcher{ 'obj-for-update' => "customer", "attr-for-update" => "tag_list"}
|
||||
%tags_with_translation{ object: 'customer', 'find-tags' => 'findTags(query)' }
|
||||
%td.bill_address{ 'ng-show' => 'columns.bill_address.visible' }
|
||||
%a{ href: '#', "ng-bind" => '::customer.bill_address | limitTo: 15', 'edit-address-dialog' => true }
|
||||
%td.ship_address{ 'ng-show' => 'columns.ship_address.visible', "ng-bind" => '::customer.ship_address | limitTo: 15' }
|
||||
%a{ href: '#', "ng-bind" => '::customer.bill_address.address1 | limitTo: 15', 'edit-address-dialog' => true }
|
||||
%td.ship_address{ 'ng-show' => 'columns.ship_address.visible', "ng-bind" => '::customer.ship_address.address1 | limitTo: 15' }
|
||||
%td.actions
|
||||
%a{ 'ng-click' => "deleteCustomer(customer)", :class => "delete-customer icon-trash no-text" }
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@ describe Api::Admin::CustomerSerializer do
|
||||
expect(tags[0]).to eq({ "text" => 'one', "rules" => nil })
|
||||
expect(tags[1]).to eq({ "text" => 'two', "rules" => 1 })
|
||||
|
||||
expect(result['bill_address']).to eq customer.bill_address.address1
|
||||
expect(result['bill_address']['id']).to eq customer.bill_address.id
|
||||
expect(result['bill_address']['address1']).to eq customer.bill_address.address1
|
||||
expect(result['ship_address']).to be nil
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user