comee_core 0.1.96 → 0.1.98
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/comee/core/agents_controller.rb +13 -0
- data/app/controllers/comee/core/application_controller.rb +15 -2
- data/app/controllers/comee/core/back_orders_controller.rb +2 -2
- data/app/controllers/comee/core/client_prices_controller.rb +3 -10
- data/app/controllers/comee/core/client_warehouses_controller.rb +13 -0
- data/app/controllers/comee/core/clients_controller.rb +42 -9
- data/app/controllers/comee/core/contacts_controller.rb +13 -0
- data/app/controllers/comee/core/customer_order_items_controller.rb +3 -2
- data/app/controllers/comee/core/customer_orders_controller.rb +3 -3
- data/app/controllers/comee/core/item_statuses_controller.rb +2 -2
- data/app/controllers/comee/core/notifications_controller.rb +4 -4
- data/app/controllers/comee/core/product_lookups_controller.rb +2 -2
- data/app/controllers/comee/core/products_controller.rb +7 -9
- data/app/controllers/comee/core/purchase_order_items_controller.rb +2 -2
- data/app/controllers/comee/core/purchase_orders_controller.rb +2 -2
- data/app/controllers/comee/core/quotation_request_items_controller.rb +2 -2
- data/app/controllers/comee/core/quotation_requests_controller.rb +8 -9
- data/app/controllers/comee/core/sales_order_items_controller.rb +1 -1
- data/app/controllers/comee/core/sales_orders_controller.rb +13 -7
- data/app/controllers/comee/core/shipment_items_controller.rb +13 -13
- data/app/controllers/comee/core/suppliers_controller.rb +4 -6
- data/app/controllers/comee/core/unit_conversions_controller.rb +1 -1
- data/app/controllers/comee/core/units_controller.rb +1 -1
- data/app/controllers/concerns/comee/core/common.rb +33 -7
- data/app/models/comee/core/agent.rb +7 -0
- data/app/models/comee/core/client.rb +4 -1
- data/app/models/comee/core/client_warehouse.rb +8 -0
- data/app/models/comee/core/contact.rb +7 -0
- data/app/models/comee/core/customer_order_item.rb +6 -0
- data/app/models/comee/core/master_price.rb +1 -0
- data/app/models/comee/core/price.rb +2 -1
- data/app/models/comee/core/sales_order.rb +1 -2
- data/app/models/comee/core/sales_order_item.rb +6 -1
- data/app/models/comee/core/supplier.rb +2 -0
- data/app/serializers/comee/core/agent_serializer.rb +7 -0
- data/app/serializers/comee/core/client_serializer.rb +4 -1
- data/app/serializers/comee/core/client_warehouse_serializer.rb +8 -0
- data/app/serializers/comee/core/contact_serializer.rb +7 -0
- data/app/serializers/comee/core/product_serializer.rb +2 -2
- data/app/serializers/comee/core/sales_order_item_serializer.rb +1 -1
- data/app/serializers/comee/core/supplier_serializer.rb +1 -0
- data/app/services/comee/core/customer_order_service.rb +7 -2
- data/config/routes.rb +7 -1
- data/db/migrate/20230728122618_create_comee_core_suppliers.rb +4 -0
- data/db/migrate/20230728123039_create_comee_core_clients.rb +4 -0
- data/db/migrate/20230728123458_create_comee_core_agents.rb +23 -0
- data/db/migrate/20230728123559_create_comee_core_contacts.rb +34 -0
- data/db/migrate/20230811102708_create_comee_core_customer_order_items.rb +1 -0
- data/db/migrate/20230812212844_create_comee_core_sales_order_items.rb +1 -0
- data/db/migrate/20230813235946_create_comee_core_master_prices.rb +2 -1
- data/db/migrate/20230814151601_create_comee_core_client_prices.rb +2 -1
- data/db/migrate/20240119100125_create_comee_core_client_warehouses.rb +15 -0
- data/lib/comee/core/version.rb +1 -1
- data/spec/factories/comee/core/agents.rb +8 -0
- data/spec/factories/comee/core/client_prices.rb +1 -1
- data/spec/factories/comee/core/client_warehouses.rb +8 -0
- data/spec/factories/comee/core/clients.rb +2 -1
- data/spec/factories/comee/core/contacts.rb +8 -0
- data/spec/factories/comee/core/customer_order_items.rb +1 -0
- data/spec/factories/comee/core/fulfillment_centers.rb +1 -1
- data/spec/factories/comee/core/master_prices.rb +1 -0
- data/spec/factories/comee/core/sales_order_items.rb +1 -0
- data/spec/factories/comee/core/suppliers.rb +1 -0
- metadata +35 -12
- data/app/models/comee/core/warehouse_shipment.rb +0 -70
- data/app/models/comee/core/warehouse_shipment_item.rb +0 -37
- data/db/migrate/20231003080017_create_comee_core_warehouse_shipments.rb +0 -17
- data/db/migrate/20231004105455_create_comee_core_warehouse_shipment_items.rb +0 -17
- data/spec/factories/comee/core/warehouse_shipment_items.rb +0 -7
- data/spec/factories/comee/core/warehouse_shipments.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b02327a6f7076613d6072fc19df00c3c19b8256dfba0e90d254d4c63f21cd87
|
4
|
+
data.tar.gz: eab3d691391e6aa77b95074449704f65f2b7320f3a920b00ef645b651351bec4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb5963d8249beac05dc28de793a53c970168f0da7f20f289e0bbb2c81562b633e85be1eb77befe79f268535b3b23174fda847b15e940e21575f1fd0502de977a
|
7
|
+
data.tar.gz: c5ceac445d220ed100a80ce759f62ac5537bb862e357dfb855552b49aa5b94880163baaae8f371a16f96db07d30491d92fa04043420c9f4084154e5f34003904
|
@@ -5,6 +5,19 @@ module Comee
|
|
5
5
|
|
6
6
|
before_action :authenticate
|
7
7
|
|
8
|
+
def render_content(data, options = {})
|
9
|
+
result = {success: true}
|
10
|
+
if params[:page]
|
11
|
+
total = data.count
|
12
|
+
data = data.then(&paginate)
|
13
|
+
result[:page] = params[:page].to_i
|
14
|
+
result[:total] = total
|
15
|
+
end
|
16
|
+
result[:data] = options.key?(:fields) ? serialize(data, include: options[:fields]) : serialize(data)
|
17
|
+
|
18
|
+
render json: result
|
19
|
+
end
|
20
|
+
|
8
21
|
def current_user
|
9
22
|
return if token.nil?
|
10
23
|
|
@@ -27,8 +40,8 @@ module Comee
|
|
27
40
|
|
28
41
|
private
|
29
42
|
|
30
|
-
def serialize(data)
|
31
|
-
ActiveModelSerializers::SerializableResource.new(data)
|
43
|
+
def serialize(data, options = {})
|
44
|
+
ActiveModelSerializers::SerializableResource.new(data, options)
|
32
45
|
end
|
33
46
|
|
34
47
|
def token
|
@@ -21,8 +21,8 @@ module Comee
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def filter
|
24
|
-
|
25
|
-
|
24
|
+
data = BackOrder.includes(:back_order_items, :supplier).ransack(params[:q]).result
|
25
|
+
render_content(data)
|
26
26
|
end
|
27
27
|
|
28
28
|
def model_params
|
@@ -5,8 +5,7 @@ module Comee
|
|
5
5
|
|
6
6
|
def index
|
7
7
|
super do
|
8
|
-
|
9
|
-
client_prices.then(&paginate)
|
8
|
+
ClientPrice.includes(:client, :product, :unit, :product_lookup).all
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
@@ -15,19 +14,13 @@ module Comee
|
|
15
14
|
client_id = client.parent_id || client.id
|
16
15
|
prices = ClientPrice.includes(:client, :product, :unit, :product_lookup)
|
17
16
|
.where(client_id: client_id)
|
18
|
-
|
19
|
-
prices = prices.then(&paginate)
|
20
|
-
|
21
|
-
render json: {success: true, data: serialize(prices), page: params[:page], total: total}
|
17
|
+
render_content(prices)
|
22
18
|
end
|
23
19
|
|
24
20
|
def filter
|
25
21
|
prices = ClientPrice.includes(:client, :product, :unit, :product_lookup)
|
26
22
|
.ransack(params[:q]).result
|
27
|
-
|
28
|
-
prices = prices.then(&paginate)
|
29
|
-
|
30
|
-
render json: {success: true, data: serialize(prices), page: params[:page], total: total}
|
23
|
+
render_content(prices)
|
31
24
|
end
|
32
25
|
|
33
26
|
private
|
@@ -4,28 +4,61 @@ module Comee
|
|
4
4
|
include Common
|
5
5
|
|
6
6
|
def filter
|
7
|
-
|
8
|
-
|
7
|
+
clients = Client.includes(:parent, :agents, :contacts, :client_warehouses).ransack(params[:q]).result
|
8
|
+
render_content(clients)
|
9
9
|
end
|
10
10
|
|
11
11
|
def consignees
|
12
|
-
client =
|
12
|
+
client = Client.find(params[:id])
|
13
13
|
render json: {success: true, data: client.consignees}
|
14
14
|
rescue StandardError => e
|
15
|
-
render json: {success: false, error: e.message}
|
15
|
+
render json: {success: false, error: e.message}, status: :unprocessable_entity
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
client =
|
20
|
-
|
18
|
+
def create_agent
|
19
|
+
client = Client.includes(:parent, :agents, :contacts, :client_warehouses).find(params[:id])
|
20
|
+
agent = Agent.new(agent_params)
|
21
|
+
if agent.save
|
22
|
+
client.agents << agent
|
23
|
+
client.save!
|
24
|
+
render_content(client)
|
25
|
+
else
|
26
|
+
render json: {success: false, error: agent.errors.full_messages[0]}, status: :unprocessable_entity
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_contact
|
31
|
+
client = Client.includes(:parent, :agents, :contacts, :client_warehouses).find(params[:id])
|
32
|
+
contact = Contact.new(contact_params)
|
33
|
+
if contact.save
|
34
|
+
client.contacts << contact
|
35
|
+
client.save!
|
36
|
+
render_content(client)
|
37
|
+
else
|
38
|
+
render json: {success: false, error: contact.errors.full_messages[0]}, status: :unprocessable_entity
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def agents
|
43
|
+
client = Client.find(params[:id])
|
44
|
+
render_content(client.agents)
|
21
45
|
rescue StandardError => e
|
22
|
-
render json: {success: false, error: e.message}
|
46
|
+
render json: {success: false, error: e.message}, status: :unprocessable_entity
|
23
47
|
end
|
24
48
|
|
25
49
|
private
|
26
50
|
|
27
51
|
def model_params
|
28
|
-
params.require(:payload).permit(:code, :name, :address, :locale, :user_id, :parent_id,
|
52
|
+
params.require(:payload).permit(:code, :name, :address, :locale, :user_id, :parent_id, :currency,
|
53
|
+
consignees: [])
|
54
|
+
end
|
55
|
+
|
56
|
+
def agent_params
|
57
|
+
params.require(:payload).permit(:name, :address, :email, :telephone)
|
58
|
+
end
|
59
|
+
|
60
|
+
def contact_params
|
61
|
+
params.require(:payload).permit(:first_name, :last_name, :email, :telephone)
|
29
62
|
end
|
30
63
|
end
|
31
64
|
end
|
@@ -9,8 +9,8 @@ module Comee
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def filter
|
12
|
-
|
13
|
-
|
12
|
+
data = CustomerOrderItem.includes(:product, :unit).ransack(params[:q]).result
|
13
|
+
render_content(data)
|
14
14
|
end
|
15
15
|
|
16
16
|
def destroy
|
@@ -32,6 +32,7 @@ module Comee
|
|
32
32
|
:customer_item_no,
|
33
33
|
:quantity,
|
34
34
|
:price,
|
35
|
+
:total_price,
|
35
36
|
:delivery_date,
|
36
37
|
:canceled,
|
37
38
|
:product_id,
|
@@ -39,8 +39,8 @@ module Comee
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def filter
|
42
|
-
|
43
|
-
|
42
|
+
orders = CustomerOrder.includes(:client, :customer_order_items).ransack(params[:q]).result
|
43
|
+
render_content(orders)
|
44
44
|
end
|
45
45
|
|
46
46
|
private
|
@@ -59,7 +59,7 @@ module Comee
|
|
59
59
|
.permit(
|
60
60
|
:order_number, :order_date, :order_terms, :consignee, :shipment_address, :final_destination,
|
61
61
|
:final_delivery_date, :handover_date, :shipping_date, :delivery_address, :invoice_address, :status, :client_id,
|
62
|
-
items: %i[customer_item_no product_id quantity price unit_id delivery_date]
|
62
|
+
items: %i[customer_item_no product_id quantity price total_price unit_id delivery_date]
|
63
63
|
)
|
64
64
|
end
|
65
65
|
|
@@ -4,8 +4,8 @@ module Comee
|
|
4
4
|
include Common
|
5
5
|
|
6
6
|
def filter
|
7
|
-
|
8
|
-
|
7
|
+
item_statuses = ItemStatus.ransack(params[:q]).result
|
8
|
+
render_content(item_statuses)
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
@@ -4,18 +4,18 @@ module Comee
|
|
4
4
|
before_action :set_notification, only: %i[mark_as_read mark_as_unread]
|
5
5
|
|
6
6
|
def index
|
7
|
-
data =
|
8
|
-
|
7
|
+
data = Notification.messages(current_user.notifications.newest_first)
|
8
|
+
render_content(data)
|
9
9
|
end
|
10
10
|
|
11
11
|
def read
|
12
12
|
data = Notification.messages(current_user.notifications.read.newest_first)
|
13
|
-
|
13
|
+
render_content(data)
|
14
14
|
end
|
15
15
|
|
16
16
|
def unread
|
17
17
|
data = Notification.messages(current_user.notifications.unread.newest_first)
|
18
|
-
|
18
|
+
render_content(data)
|
19
19
|
end
|
20
20
|
|
21
21
|
def mark_as_read
|
@@ -5,37 +5,35 @@ module Comee
|
|
5
5
|
|
6
6
|
def index
|
7
7
|
super do
|
8
|
-
|
9
|
-
products.then(&paginate)
|
8
|
+
Product.leafs
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
13
12
|
def show
|
14
13
|
super do
|
15
|
-
|
16
|
-
product
|
14
|
+
Comee::Core::Product.with_attached_images.find(params[:id])
|
17
15
|
end
|
18
16
|
end
|
19
17
|
|
20
18
|
def master_prices
|
21
19
|
data = MasterPrice.includes(:product_lookup, :supplier, :product)
|
22
20
|
.where(product_id: price_params[:product_ids])
|
23
|
-
|
21
|
+
render_content(data)
|
24
22
|
end
|
25
23
|
|
26
24
|
def client_prices
|
27
25
|
data = ClientPrice.where(product_id: price_params[:product_ids])
|
28
|
-
|
26
|
+
render_content(data)
|
29
27
|
end
|
30
28
|
|
31
29
|
def categories
|
32
30
|
root = Product.find_by(code: "root")
|
33
|
-
|
31
|
+
render_content(root.children)
|
34
32
|
end
|
35
33
|
|
36
34
|
def filter
|
37
|
-
|
38
|
-
|
35
|
+
data = Product.ransack(params[:q]).result
|
36
|
+
render_content(data)
|
39
37
|
end
|
40
38
|
|
41
39
|
private
|
@@ -4,8 +4,8 @@ module Comee
|
|
4
4
|
include Common
|
5
5
|
|
6
6
|
def filter
|
7
|
-
|
8
|
-
|
7
|
+
data = PurchaseOrderItem.ransack(params[:q]).result
|
8
|
+
render_content(data)
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
@@ -4,8 +4,8 @@ module Comee
|
|
4
4
|
include Common
|
5
5
|
|
6
6
|
def filter
|
7
|
-
|
8
|
-
|
7
|
+
data = Comee::Core::PurchaseOrder.ransack(params[:q]).result
|
8
|
+
render_content(data)
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
@@ -9,8 +9,8 @@ module Comee
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def filter
|
12
|
-
|
13
|
-
|
12
|
+
data = QuotationRequestItem.includes(:product, :quotation_request, :unit).ransack(params[:q]).result
|
13
|
+
render_content(data)
|
14
14
|
end
|
15
15
|
|
16
16
|
def destroy
|
@@ -10,9 +10,8 @@ module Comee
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def filter
|
13
|
-
|
14
|
-
|
15
|
-
render json: {success: true, data: serialize(query.includes(:client))}
|
13
|
+
data = QuotationRequest.includes(:client).ransack(params[:q]).result
|
14
|
+
render_content(data)
|
16
15
|
end
|
17
16
|
|
18
17
|
def rfq_products_for_client
|
@@ -20,20 +19,20 @@ module Comee
|
|
20
19
|
root = Product.roots.first
|
21
20
|
ids = root.indirect_ids - client_products
|
22
21
|
products = Product.where(id: ids)
|
23
|
-
|
22
|
+
render_content(products)
|
24
23
|
end
|
25
24
|
|
26
25
|
def create_request_with_items
|
27
26
|
service = QuotationRequestService.new
|
28
27
|
parameters = rfq_params.to_h.deep_symbolize_keys
|
29
28
|
result = service.create_request_with_items(parameters)
|
30
|
-
|
29
|
+
render_content(result)
|
31
30
|
end
|
32
31
|
|
33
32
|
def submit
|
34
33
|
service = QuotationRequestService.new
|
35
34
|
rfq = service.submit(params[:id])
|
36
|
-
|
35
|
+
render_content(rfq)
|
37
36
|
rescue StandardError => e
|
38
37
|
render json: {success: false, error: e.message}
|
39
38
|
end
|
@@ -41,7 +40,7 @@ module Comee
|
|
41
40
|
def submit_for_confirmation
|
42
41
|
service = QuotationRequestService.new
|
43
42
|
rfq = service.submit_for_confirmation(params[:id])
|
44
|
-
|
43
|
+
render_content(rfq)
|
45
44
|
rescue StandardError => e
|
46
45
|
render json: {success: false, error: e.message}
|
47
46
|
end
|
@@ -49,7 +48,7 @@ module Comee
|
|
49
48
|
def confirm
|
50
49
|
service = QuotationRequestService.new
|
51
50
|
rfq = service.confirm(params[:id])
|
52
|
-
|
51
|
+
render_content(rfq)
|
53
52
|
rescue StandardError => e
|
54
53
|
render json: {success: false, error: e.message}
|
55
54
|
end
|
@@ -57,7 +56,7 @@ module Comee
|
|
57
56
|
def convert
|
58
57
|
service = QuotationRequestService.new
|
59
58
|
order = service.convert_to_order(params[:id])
|
60
|
-
|
59
|
+
render_content(order)
|
61
60
|
rescue StandardError => e
|
62
61
|
render json: {success: false, error: e.message}
|
63
62
|
end
|
@@ -6,35 +6,41 @@ module Comee
|
|
6
6
|
|
7
7
|
def index
|
8
8
|
super do
|
9
|
+
data = SalesOrder.includes(:customer_order, :fulfillment_center, :sales_order_items, :client).all
|
9
10
|
[
|
10
|
-
|
11
|
-
|
11
|
+
data,
|
12
|
+
fields: ["client", "customer_order", "sales_order_items", "sales_order_items.product", "sales_order_items.unit"]
|
12
13
|
]
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
17
|
def filter
|
17
|
-
|
18
|
-
|
18
|
+
data = SalesOrder.includes(
|
19
|
+
:customer_order,
|
20
|
+
:client,
|
21
|
+
:fulfillment_center,
|
22
|
+
:sales_order_items
|
23
|
+
).ransack(params[:q]).result
|
24
|
+
render_content(data)
|
19
25
|
end
|
20
26
|
|
21
27
|
def submit
|
22
28
|
order = @service.submit(params[:id])
|
23
|
-
|
29
|
+
render_content(order)
|
24
30
|
rescue StandardError => e
|
25
31
|
render json: {success: false, error: e.message}
|
26
32
|
end
|
27
33
|
|
28
34
|
def confirm
|
29
35
|
order = @service.confirm(params[:id])
|
30
|
-
|
36
|
+
render_content(order)
|
31
37
|
rescue StandardError => e
|
32
38
|
render json: {success: false, error: e.message}
|
33
39
|
end
|
34
40
|
|
35
41
|
def cancel
|
36
42
|
order = @service.cancel(params[:id])
|
37
|
-
|
43
|
+
render_content(order)
|
38
44
|
rescue StandardError => e
|
39
45
|
render json: {success: false, error: e.message}
|
40
46
|
end
|
@@ -7,27 +7,27 @@ module Comee
|
|
7
7
|
super do
|
8
8
|
[
|
9
9
|
ShipmentItem.includes(sales_order_item: [sales_order: :client]).all,
|
10
|
-
|
10
|
+
fields: ["sales_order_item.sales_order.client"]
|
11
11
|
]
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
def filter
|
16
|
-
|
17
|
-
options = {
|
18
|
-
|
16
|
+
shipment_item = ShipmentItem.includes(:sales_order_item).ransack(params[:q]).result
|
17
|
+
options = {fields: ["sales_order_item.sales_order.client"]}
|
18
|
+
render_content(shipment_item, options)
|
19
19
|
end
|
20
20
|
|
21
21
|
def filter_for_client
|
22
|
-
shipment_items =
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
22
|
+
shipment_items = ShipmentItem.joins(sales_order_item: :sales_order)
|
23
|
+
.where(
|
24
|
+
comee_core_sales_order_items: {
|
25
|
+
comee_core_sales_orders: {
|
26
|
+
client_id: params[:id]
|
27
|
+
}
|
28
|
+
}
|
29
|
+
)
|
30
|
+
render_content(shipment_items)
|
31
31
|
end
|
32
32
|
|
33
33
|
def filter_with_status
|
@@ -5,21 +5,19 @@ module Comee
|
|
5
5
|
|
6
6
|
def index
|
7
7
|
super do
|
8
|
-
Supplier.
|
8
|
+
Supplier.includes(:currency).all
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
def filter
|
13
|
-
suppliers =
|
14
|
-
|
15
|
-
suppliers = suppliers.then(&paginate)
|
16
|
-
render json: {success: true, data: serialize(suppliers), page: params[:page], total: total}
|
13
|
+
suppliers = Supplier.includes(:currency).ransack(params[:q]).result
|
14
|
+
render_content(suppliers)
|
17
15
|
end
|
18
16
|
|
19
17
|
private
|
20
18
|
|
21
19
|
def model_params
|
22
|
-
params.require(:payload).permit(:code, :name, :address, :locale)
|
20
|
+
params.require(:payload).permit(:code, :name, :address, :locale, :currency_id)
|
23
21
|
end
|
24
22
|
end
|
25
23
|
end
|
@@ -2,6 +2,7 @@ module Comee
|
|
2
2
|
module Core
|
3
3
|
module Common
|
4
4
|
extend ActiveSupport::Concern
|
5
|
+
include Pagination
|
5
6
|
|
6
7
|
included do
|
7
8
|
before_action :set_clazz
|
@@ -15,23 +16,48 @@ module Comee
|
|
15
16
|
incoming = yield
|
16
17
|
if incoming.instance_of?(Array)
|
17
18
|
data, options = incoming
|
19
|
+
elsif incoming.instance_of?(Hash)
|
20
|
+
options = incoming
|
18
21
|
else
|
19
22
|
data = incoming
|
20
23
|
end
|
21
24
|
else
|
22
25
|
data = @clazz.all
|
23
26
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
total = data.count
|
28
|
+
data = data.then(&paginate) if params[:page]
|
29
|
+
result = {
|
30
|
+
success: true,
|
31
|
+
data: options.key?(:fields) ? serialize(data, include: options[:fields]) : serialize(data)
|
32
|
+
}
|
33
|
+
if params[:page]
|
34
|
+
result[:page] = params[:page]
|
35
|
+
result[:total] = total
|
30
36
|
end
|
37
|
+
|
38
|
+
render json: result
|
31
39
|
end
|
32
40
|
|
33
41
|
def show
|
34
|
-
|
42
|
+
data = nil
|
43
|
+
options = {}
|
44
|
+
if block_given?
|
45
|
+
incoming = yield
|
46
|
+
if incoming.instance_of?(Array)
|
47
|
+
data, options = incoming
|
48
|
+
elsif incoming.instance_of?(Hash)
|
49
|
+
options = incoming
|
50
|
+
else
|
51
|
+
data = incoming
|
52
|
+
end
|
53
|
+
else
|
54
|
+
data = @obj
|
55
|
+
end
|
56
|
+
result = {
|
57
|
+
success: true,
|
58
|
+
data: options.key?(:fields) ? serialize(data, include: options[:fields]) : serialize(data)
|
59
|
+
}
|
60
|
+
render json: result
|
35
61
|
end
|
36
62
|
|
37
63
|
def create
|