diff --git a/Gemfile b/Gemfile index 29f31c2e1..0fb085219 100755 --- a/Gemfile +++ b/Gemfile @@ -43,6 +43,7 @@ gem 'oj', '2.10.2' # 2.10.3 causes a 'too deeply nested' error gem 'oj_mimic_json' gem 'redis' gem 'redis-rails', '~> 5.0.2' +gem 'sprockets', '~>3.7.2' gem 'rollbar' gem 'apipie-rails' , git: "https://github.com/Apipie/apipie-rails.git", branch: 'master' gem "go_go_van_api", git: "git@github.com:crossroads/go_go_van_api.git", branch: 'master' diff --git a/Gemfile.lock b/Gemfile.lock index 8ffc02360..1656eb518 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -128,7 +128,7 @@ GEM codeclimate-test-reporter (1.0.8) simplecov (<= 0.13) coderay (1.1.1) - concurrent-ruby (1.0.4) + concurrent-ruby (1.0.5) connection_pool (2.2.0) crack (0.4.3) safe_yaml (~> 1.0.0) @@ -234,7 +234,7 @@ GEM method_source (~> 0.8.1) slop (~> 3.4) puma (3.0.2) - rack (1.6.9) + rack (1.6.10) rack-cors (0.4.0) rack-protection (2.0.1) rack @@ -359,7 +359,7 @@ GEM spring (1.6.4) spring-commands-rspec (1.0.4) spring (>= 0.9.1) - sprockets (3.7.1) + sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) sprockets-rails (3.2.0) @@ -463,6 +463,7 @@ DEPENDENCIES sinatra spring spring-commands-rspec + sprockets (~> 3.7.2) state_machine timecop traco diff --git a/app/controllers/api/v1/items_controller.rb b/app/controllers/api/v1/items_controller.rb index 71e21b36c..1af718da5 100644 --- a/app/controllers/api/v1/items_controller.rb +++ b/app/controllers/api/v1/items_controller.rb @@ -96,7 +96,7 @@ def stockit_serializer def update_offer_state(offer) offer.items.reload - if [:reviewed, :scheduled].include?(offer.state_name) && offer.items.all?{|i| i.state_name == :rejected} + if [:reviewed, :scheduled].include?(offer.state_name) && offer.items.all?{ |i| i.state_name == :rejected } offer.re_review! end end diff --git a/app/models/order.rb b/app/models/order.rb index f97d868a9..b8b6e855d 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -14,6 +14,7 @@ class Order < ActiveRecord::Base belongs_to :process_completed_by, class_name: 'User' belongs_to :dispatch_started_by, class_name: 'User' belongs_to :closed_by, class_name: 'User' + belongs_to :submitted_by, class_name: 'User' belongs_to :stockit_local_order, -> { joins("inner join orders on orders.detail_id = stockit_local_orders.id and orders.detail_type = 'LocalOrder'") }, foreign_key: 'detail_id' has_many :packages @@ -115,20 +116,22 @@ def set_initial_state end before_transition on: :submit do |order| + order.submitted_at = Time.now + order.submitted_by = User.current_user order.add_to_stockit end before_transition on: :start_processing do |order| if order.submitted? order.processed_at = Time.now - order.processed_by_id = User.current_user.id + order.processed_by = User.current_user end end before_transition on: :redesignate_cancelled_order do |order| if order.cancelled? order.processed_at = Time.now - order.processed_by_id = User.current_user.id + order.processed_by = User.current_user order.nullify_columns(:process_completed_at, :process_completed_by_id, :cancelled_at, :cancelled_by_id, :dispatch_started_by_id, :dispatch_started_at) end @@ -137,20 +140,20 @@ def set_initial_state before_transition on: :start_dispatching do |order| if order.awaiting_dispatch? order.dispatch_started_at = Time.now - order.dispatch_started_by_id = User.current_user.id + order.dispatch_started_by = User.current_user end end before_transition on: :finish_processing do |order| if order.processing? order.process_completed_at = Time.now - order.process_completed_by_id = User.current_user.id + order.process_completed_by = User.current_user end end before_transition on: :cancel do |order| order.cancelled_at = Time.now - order.cancelled_by_id = User.current_user.id + order.cancelled_by = User.current_user order.orders_packages.each do |orders_package| orders_package.cancel end @@ -159,7 +162,7 @@ def set_initial_state before_transition on: :close do |order| if order.dispatching? order.closed_at = Time.now - order.closed_by_id = User.current_user.id + order.closed_by = User.current_user end end @@ -172,7 +175,7 @@ def set_initial_state before_transition on: :reopen do |order| if order.closed? order.dispatch_started_at = Time.now - order.dispatch_started_by_id = User.current_user.id + order.dispatch_started_by = User.current_user order.nullify_columns(:closed_at, :closed_by_id) end end diff --git a/app/serializers/api/v1/order_serializer.rb b/app/serializers/api/v1/order_serializer.rb index 07a9fc6b8..ea38fd506 100644 --- a/app/serializers/api/v1/order_serializer.rb +++ b/app/serializers/api/v1/order_serializer.rb @@ -6,7 +6,7 @@ class OrderSerializer < ApplicationSerializer :country_name, :state, :purpose_description, :created_by_id, :item_ids, :gc_organisation_id, :processed_at, :processed_by_id, :cancelled_at, :cancelled_by_id, :process_completed_at, :process_completed_by_id, :closed_at, :closed_by_id, :dispatch_started_at, - :dispatch_started_by_id + :dispatch_started_by_id, :submitted_at, :submitted_by_id has_one :created_by, serializer: UserProfileSerializer, root: :user has_one :stockit_contact, serializer: StockitContactSerializer, root: :contact @@ -18,6 +18,12 @@ class OrderSerializer < ApplicationSerializer has_many :cart_packages, serializer: BrowsePackageSerializer, root: :packages has_many :orders_packages, serializer: OrdersPackageSerializer has_many :orders_purposes, serializer: OrdersPurposeSerializer + has_one :closed_by, serializer: UserSerializer + has_one :processed_by, serializer: UserSerializer + has_one :cancelled_by, serializer: UserSerializer + has_one :process_completed_by, serializer: UserSerializer + has_one :dispatch_started_by, serializer: UserSerializer + has_one :submitted_by, serializer: UserSerializer def include_packages? @options[:include_packages] diff --git a/app/serializers/api/v1/order_transport_serializer.rb b/app/serializers/api/v1/order_transport_serializer.rb index fbdb5acab..5f86f89a5 100644 --- a/app/serializers/api/v1/order_transport_serializer.rb +++ b/app/serializers/api/v1/order_transport_serializer.rb @@ -2,11 +2,20 @@ module Api::V1 class OrderTransportSerializer < ApplicationSerializer embed :ids, include: true attributes :id, :order_id, :scheduled_at, :timeslot, :gogovan_transport_id, - :transport_type, :need_english, :need_cart, :need_carry, :designation_id + :transport_type, :need_english, :need_cart, :need_carry, :designation_id, + :need_over_6ft, :remove_net, :need_over_six_ft has_one :contact, serializer: ContactSerializer has_one :gogovan_order, serializer: GogovanOrderSerializer + def need_over_six_ft + object.need_over_6ft + end + + def need_over_six_ft__sql + "need_over_6ft" + end + def designation_id object.order_id end diff --git a/app/serializers/api/v1/organisation_without_order_serializer.rb b/app/serializers/api/v1/organisation_without_order_serializer.rb new file mode 100644 index 000000000..e204adbc9 --- /dev/null +++ b/app/serializers/api/v1/organisation_without_order_serializer.rb @@ -0,0 +1,9 @@ +module Api::V1 + class OrganisationWithoutOrderSerializer < ApplicationSerializer + embed :ids, include: true + + attributes :id, :name_en, :name_zh_tw, :description_en, :description_zh_tw, :registration, + :website, :organisation_type_id, :district_id, :country_id, :created_at, + :updated_at + end +end diff --git a/app/serializers/api/v1/organisations_user_serializer.rb b/app/serializers/api/v1/organisations_user_serializer.rb index e54b048e1..9368c595e 100644 --- a/app/serializers/api/v1/organisations_user_serializer.rb +++ b/app/serializers/api/v1/organisations_user_serializer.rb @@ -3,6 +3,6 @@ class OrganisationsUserSerializer < ActiveModel::Serializer embed :ids, include: true attributes :id, :user_id, :organisation_id, :position has_one :user, serializer: UserSerializer - # has_one :organisation, serializer: OrganisationSerializer + has_one :organisation, serializer: OrganisationWithoutOrderSerializer end end diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index 989f56de4..c2b6ae8ef 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -11,7 +11,7 @@ GGV_POLL_JOB_WAIT_TIME = 60.seconds GGV_POLL_JOB_WAIT_TIME_FOR_ONLINE_DONOR = 30.seconds SYSTEM_USER_MOBILE = "+85264522773" -GOODCITY_NUMBER = "+85258088700" +GOODCITY_NUMBER = "+85222729348" TWILIO_QUEUE_WAIT_TIME = 30 STOCKIT_PREFIX = "X" APP_NAME_AND_LOGIN_PERMISSION_MAPPING = { diff --git a/db/migrate/20180620045905_add_submitted_by_id_to_orders.rb b/db/migrate/20180620045905_add_submitted_by_id_to_orders.rb new file mode 100644 index 000000000..38b96c760 --- /dev/null +++ b/db/migrate/20180620045905_add_submitted_by_id_to_orders.rb @@ -0,0 +1,5 @@ +class AddSubmittedByIdToOrders < ActiveRecord::Migration + def change + add_column :orders, :submitted_by_id, :integer + end +end diff --git a/db/migrate/20180620045951_add_submitted_at_to_orders.rb b/db/migrate/20180620045951_add_submitted_at_to_orders.rb new file mode 100644 index 000000000..0a0f9793e --- /dev/null +++ b/db/migrate/20180620045951_add_submitted_at_to_orders.rb @@ -0,0 +1,5 @@ +class AddSubmittedAtToOrders < ActiveRecord::Migration + def change + add_column :orders, :submitted_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 07a5047fd..147714f63 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180612100305) do +ActiveRecord::Schema.define(version: 20180620045951) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -279,6 +279,8 @@ t.integer "closed_by_id" t.datetime "dispatch_started_at" t.integer "dispatch_started_by_id" + t.integer "submitted_by_id" + t.datetime "submitted_at" end add_index "orders", ["code"], name: "orders_code_idx", using: :gin diff --git a/spec/serializers/api/v1/organisation_without_order_serializer_spec.rb b/spec/serializers/api/v1/organisation_without_order_serializer_spec.rb new file mode 100644 index 000000000..8e87174e7 --- /dev/null +++ b/spec/serializers/api/v1/organisation_without_order_serializer_spec.rb @@ -0,0 +1,25 @@ +require 'rails_helper' + +describe Api::V1::OrganisationWithoutOrderSerializer do + let(:organisation_without_order) { build(:organisation) } + let(:serializer) { Api::V1::OrganisationWithoutOrderSerializer.new(organisation_without_order) } + let(:json) { JSON.parse( serializer.to_json ) } + + it "creates JSON" do + expect(json['organisation_without_order']['id']).to eql(organisation_without_order.id) + expect(json['organisation_without_order']['name_en']).to eql(organisation_without_order.name_en) + expect(json['organisation_without_order']['name_zh_tw']).to eql(organisation_without_order.name_zh_tw) + expect(json['organisation_without_order']['description_en']).to eql(organisation_without_order.description_en) + expect(json['organisation_without_order']['description_zh_tw']).to eql(organisation_without_order.description_zh_tw) + expect(json['organisation_without_order']['registration']).to eql(organisation_without_order.registration) + expect(json['organisation_without_order']['organisation_type_id']).to eql(organisation_without_order.organisation_type_id) + expect(json['organisation_without_order']['district_id']).to eql(organisation_without_order.district_id) + expect(json['organisation_without_order']['country_id']).to eql(organisation_without_order.country_id) + end + + it "translates JSON" do + I18n.locale = 'zh-tw' + expect(json['organisation_without_order']['name_zh_tw']).to eql(organisation_without_order.name_zh_tw) + expect(json['organisation_without_order']['description_zh_tw']).to eql(organisation_without_order.description_zh_tw) + end +end