mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-28 09:24:24 +01:00
rename operator id to operator_profile_id in order
This commit is contained in:
parent
7c59d44785
commit
49aa54193d
@ -16,13 +16,13 @@ class API::CartController < API::ApiController
|
||||
state: 'cart').last
|
||||
end
|
||||
if current_user&.privileged?
|
||||
@order = Order.where(operator_id: current_user.id,
|
||||
@order = Order.where(operator_profile_id: current_user.invoicing_profile.id,
|
||||
state: 'cart').last
|
||||
end
|
||||
end
|
||||
if @order
|
||||
@order.update(statistic_profile_id: current_user.statistic_profile.id) if @order.statistic_profile_id.nil? && current_user&.member?
|
||||
@order.update(operator_id: current_user.id) if @order.operator_id.nil? && current_user&.privileged?
|
||||
@order.update(operator_profile_id: current_user.invoicing_profile.id) if @order.operator_profile_id.nil? && current_user&.privileged?
|
||||
end
|
||||
@order ||= Cart::CreateService.new.call(current_user)
|
||||
render 'api/orders/show'
|
||||
|
@ -8,7 +8,7 @@ export interface Order {
|
||||
token: string,
|
||||
statistic_profile_id?: number,
|
||||
user?: User,
|
||||
operator_id?: number,
|
||||
operator_profile_id?: number,
|
||||
reference?: string,
|
||||
state?: string,
|
||||
total?: number,
|
||||
|
@ -3,6 +3,7 @@
|
||||
# Order is a model for the user hold information of order
|
||||
class Order < ApplicationRecord
|
||||
belongs_to :statistic_profile
|
||||
belongs_to :operator_profile, class_name: 'InvoicingProfile'
|
||||
has_many :order_items, dependent: :destroy
|
||||
|
||||
ALL_STATES = %w[cart in_progress ready canceled return].freeze
|
||||
|
@ -12,7 +12,7 @@ class Cart::CreateService
|
||||
if user
|
||||
order_param[:statistic_profile_id] = user.statistic_profile.id if user.member?
|
||||
|
||||
order_param[:operator_id] = user.id if user.privileged?
|
||||
order_param[:operator_profile_id] = user.invoicing_profile.id if user.privileged?
|
||||
end
|
||||
Order.create!(order_param)
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.extract! order, :id, :token, :statistic_profile_id, :operator_id, :reference, :state, :created_at
|
||||
json.extract! order, :id, :token, :statistic_profile_id, :operator_profile_id, :reference, :state, :created_at
|
||||
json.total order.total / 100.0 if order.total.present?
|
||||
if order&.statistic_profile&.user
|
||||
json.user do
|
||||
|
@ -0,0 +1,7 @@
|
||||
class RenameOperatorIdToOperatorProfileIdInOrder < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
rename_column :orders, :operator_id, :operator_profile_id
|
||||
add_index :orders, :operator_profile_id
|
||||
add_foreign_key :orders, :invoicing_profiles, column: :operator_profile_id, primary_key: :id
|
||||
end
|
||||
end
|
@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2022_08_26_091819) do
|
||||
ActiveRecord::Schema.define(version: 2022_08_26_093503) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "fuzzystrmatch"
|
||||
@ -460,7 +460,7 @@ ActiveRecord::Schema.define(version: 2022_08_26_091819) do
|
||||
|
||||
create_table "orders", force: :cascade do |t|
|
||||
t.bigint "statistic_profile_id"
|
||||
t.integer "operator_id"
|
||||
t.integer "operator_profile_id"
|
||||
t.string "token"
|
||||
t.string "reference"
|
||||
t.string "state"
|
||||
@ -471,6 +471,7 @@ ActiveRecord::Schema.define(version: 2022_08_26_091819) do
|
||||
t.integer "wallet_amount"
|
||||
t.integer "wallet_transaction_id"
|
||||
t.string "payment_method"
|
||||
t.index ["operator_profile_id"], name: "index_orders_on_operator_profile_id"
|
||||
t.index ["statistic_profile_id"], name: "index_orders_on_statistic_profile_id"
|
||||
end
|
||||
|
||||
@ -1164,6 +1165,7 @@ ActiveRecord::Schema.define(version: 2022_08_26_091819) do
|
||||
add_foreign_key "invoices", "wallet_transactions"
|
||||
add_foreign_key "invoicing_profiles", "users"
|
||||
add_foreign_key "order_items", "orders"
|
||||
add_foreign_key "orders", "invoicing_profiles", column: "operator_profile_id"
|
||||
add_foreign_key "orders", "statistic_profiles"
|
||||
add_foreign_key "organizations", "invoicing_profiles"
|
||||
add_foreign_key "payment_gateway_objects", "payment_gateway_objects"
|
||||
|
Loading…
Reference in New Issue
Block a user