c80_shared 0.1.62 → 0.1.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/serializers/boat_serializer.rb +5 -0
- data/lib/c80_shared/version.rb +1 -1
- data/lib/c80_shared.rb +1 -1
- data/scratch_105___02.txt +13 -0
- metadata +3 -44
- data/app/repositories/accounts/admin_account_repository.rb +0 -35
- data/app/repositories/accounts/central_agent_account_repository.rb +0 -46
- data/app/repositories/accounts/client_account_repository.rb +0 -43
- data/app/repositories/accounts/manager_account_repository.rb +0 -35
- data/app/repositories/accounts/manager_guest_account_repository.rb +0 -35
- data/app/repositories/accounts/moderator_account_repository.rb +0 -35
- data/app/schemas/base.rb +0 -69
- data/app/schemas/base_boat_schema.rb +0 -235
- data/app/schemas/central_agent/save_boat_schema.rb +0 -57
- data/app/services/abstract_prices_service.rb +0 -70
- data/app/services/boats/boat_prices_save_service.rb +0 -81
- data/app/services/boats/boat_sale_prices_save_service.rb +0 -60
- data/app/services/boats/dimension_service.rb +0 -44
- data/app/services/central_agent/save_boat_service.rb +0 -111
- data/app/services/lease/create_broadcast_inquiry_service.rb +0 -62
- data/app/services/lease/destroy_inquiry_service.rb +0 -5
- data/config/initializers/core_ext/active_record_log_subscriber.rb +0 -60
- data/config/initializers/core_ext/string.rb +0 -62
- data/lib/dry/errors.rb +0 -77
- data/lib/dry/rule.rb +0 -75
- data/lib/dry/rules/and.rb +0 -13
- data/lib/dry/rules/between.rb +0 -20
- data/lib/dry/rules/binary.rb +0 -18
- data/lib/dry/rules/collection.rb +0 -18
- data/lib/dry/rules/composite.rb +0 -21
- data/lib/dry/rules/equal.rb +0 -20
- data/lib/dry/rules/format.rb +0 -20
- data/lib/dry/rules/greater_than.rb +0 -20
- data/lib/dry/rules/greater_than_or_equal.rb +0 -20
- data/lib/dry/rules/included.rb +0 -20
- data/lib/dry/rules/length_between.rb +0 -20
- data/lib/dry/rules/length_equal.rb +0 -20
- data/lib/dry/rules/less_than.rb +0 -20
- data/lib/dry/rules/less_than_or_equal.rb +0 -20
- data/lib/dry/rules/max_length.rb +0 -20
- data/lib/dry/rules/min_length.rb +0 -20
- data/lib/dry/rules/not_equal.rb +0 -20
- data/lib/dry/rules/or.rb +0 -15
- data/lib/dry/rules/present.rb +0 -23
- data/lib/dry/rules/then.rb +0 -15
- data/lib/dry/rules_factory.rb +0 -134
- data/lib/dry/schema.rb +0 -148
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a839dc2411230b3fe6219bc77ea6ac3a3fee81e3b0901bf76f9c9a184b5ef037
|
4
|
+
data.tar.gz: 6f7b105a5ed6766399be2ae11a95cebdcff65b77d5b054390203ab2200b4a74c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c62d3f733e49b298fb449c5ec0d52e7b3d2a2d6107cd87182e162717857a98032c2156dd13b6e158a875a279760cc05c50a169321609ed93b4d94ee080fdbaa3
|
7
|
+
data.tar.gz: 2dfe9219c5b5d2a92bdfb124957cb00a66a4f402c16904448deffb3db5b267b9e3df7bd98b2194df03bc452d5dccae57e1b33bcf5bf71aa1fbf7cc96d3e5d651
|
@@ -28,6 +28,7 @@ class BoatSerializer < AbstractSerializer
|
|
28
28
|
builder
|
29
29
|
built_year
|
30
30
|
charter_details
|
31
|
+
charter_deposit
|
31
32
|
crew_total
|
32
33
|
crew_cabins
|
33
34
|
description
|
@@ -518,6 +519,10 @@ class BoatSerializer < AbstractSerializer
|
|
518
519
|
{ charter_details: boat.charter_details }
|
519
520
|
end
|
520
521
|
|
522
|
+
def charter_deposit(boat)
|
523
|
+
{ charter_deposit: boat.charter_deposit }
|
524
|
+
end
|
525
|
+
|
521
526
|
def serialize_opts
|
522
527
|
locale = ::Dicts::Locale.find_by_index @opts[:locale].to_s
|
523
528
|
uol = ::Dicts::Length.find_by_index @opts[:uol]
|
data/lib/c80_shared/version.rb
CHANGED
data/lib/c80_shared.rb
CHANGED
@@ -8,7 +8,7 @@ end.call
|
|
8
8
|
# загружаем все классы из директории app
|
9
9
|
lambda do
|
10
10
|
lib_path = File.expand_path('../../app', __FILE__)
|
11
|
-
dir_names = %w[dicts helpers serializers
|
11
|
+
dir_names = %w[dicts helpers serializers] # order matters!
|
12
12
|
|
13
13
|
dir_names.each do |dir|
|
14
14
|
dir_path = '%s/%s/**/*.rb' % [lib_path, dir]
|
@@ -0,0 +1,13 @@
|
|
1
|
+
ФУНКЦИЯ-1: показ блока с ценами аренды на странице просмотра лодки
|
2
|
+
На странице должна отобразиться минимальная цена аренды и кнопка 'request to book'
|
3
|
+
|
4
|
+
ПРЕДЫСТОРИЯ-2:
|
5
|
+
Допустим юзер входит на главную страницу
|
6
|
+
И кликает по лодке из блока FEATURES BOATS FOR RENT (http://localhost:3000/en/boat/carpe_diem?for=rent)
|
7
|
+
И лодка на продажу
|
8
|
+
|
9
|
+
@correct
|
10
|
+
СЦЕНАРИЙ:
|
11
|
+
На странице должна отобразиться минимальная цена аренды и кнопка 'request to book'
|
12
|
+
На странице не должно быть блока `contact seller`
|
13
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: c80_shared
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.63
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- C80609A
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -71,15 +71,6 @@ files:
|
|
71
71
|
- app/helpers/custom/price_helper.rb
|
72
72
|
- app/helpers/custom/select_helper.rb
|
73
73
|
- app/helpers/site/time_helper.rb
|
74
|
-
- app/repositories/accounts/admin_account_repository.rb
|
75
|
-
- app/repositories/accounts/central_agent_account_repository.rb
|
76
|
-
- app/repositories/accounts/client_account_repository.rb
|
77
|
-
- app/repositories/accounts/manager_account_repository.rb
|
78
|
-
- app/repositories/accounts/manager_guest_account_repository.rb
|
79
|
-
- app/repositories/accounts/moderator_account_repository.rb
|
80
|
-
- app/schemas/base.rb
|
81
|
-
- app/schemas/base_boat_schema.rb
|
82
|
-
- app/schemas/central_agent/save_boat_schema.rb
|
83
74
|
- app/serializers/account_serializer.rb
|
84
75
|
- app/serializers/boat_location_serializer.rb
|
85
76
|
- app/serializers/boat_price_serializer.rb
|
@@ -97,21 +88,12 @@ files:
|
|
97
88
|
- app/serializers/lib/boats/dimensions.rb
|
98
89
|
- app/serializers/lib/boats/rent_price_per_season.rb
|
99
90
|
- app/serializers/lib/boats/sale_price.rb
|
100
|
-
- app/services/abstract_prices_service.rb
|
101
|
-
- app/services/boats/boat_prices_save_service.rb
|
102
|
-
- app/services/boats/boat_sale_prices_save_service.rb
|
103
|
-
- app/services/boats/dimension_service.rb
|
104
|
-
- app/services/central_agent/save_boat_service.rb
|
105
|
-
- app/services/lease/create_broadcast_inquiry_service.rb
|
106
|
-
- app/services/lease/destroy_inquiry_service.rb
|
107
91
|
- app/services/users/find_or_generate_email_token_service.rb
|
108
92
|
- app/services/users/generate_email_token_service.rb
|
109
93
|
- bin/console
|
110
94
|
- bin/rails
|
111
95
|
- bin/setup
|
112
96
|
- c80_shared.gemspec
|
113
|
-
- config/initializers/core_ext/active_record_log_subscriber.rb
|
114
|
-
- config/initializers/core_ext/string.rb
|
115
97
|
- config/locales/boat/en.yml
|
116
98
|
- config/locales/boat/ru.yml
|
117
99
|
- config/locales/dicts/account_type/en.yml
|
@@ -141,30 +123,7 @@ files:
|
|
141
123
|
- lib/c80_shared/middleware/images_proxy.rb
|
142
124
|
- lib/c80_shared/token_generator.rb
|
143
125
|
- lib/c80_shared/version.rb
|
144
|
-
-
|
145
|
-
- lib/dry/rule.rb
|
146
|
-
- lib/dry/rules/and.rb
|
147
|
-
- lib/dry/rules/between.rb
|
148
|
-
- lib/dry/rules/binary.rb
|
149
|
-
- lib/dry/rules/collection.rb
|
150
|
-
- lib/dry/rules/composite.rb
|
151
|
-
- lib/dry/rules/equal.rb
|
152
|
-
- lib/dry/rules/format.rb
|
153
|
-
- lib/dry/rules/greater_than.rb
|
154
|
-
- lib/dry/rules/greater_than_or_equal.rb
|
155
|
-
- lib/dry/rules/included.rb
|
156
|
-
- lib/dry/rules/length_between.rb
|
157
|
-
- lib/dry/rules/length_equal.rb
|
158
|
-
- lib/dry/rules/less_than.rb
|
159
|
-
- lib/dry/rules/less_than_or_equal.rb
|
160
|
-
- lib/dry/rules/max_length.rb
|
161
|
-
- lib/dry/rules/min_length.rb
|
162
|
-
- lib/dry/rules/not_equal.rb
|
163
|
-
- lib/dry/rules/or.rb
|
164
|
-
- lib/dry/rules/present.rb
|
165
|
-
- lib/dry/rules/then.rb
|
166
|
-
- lib/dry/rules_factory.rb
|
167
|
-
- lib/dry/schema.rb
|
126
|
+
- scratch_105___02.txt
|
168
127
|
homepage: http://google.com
|
169
128
|
licenses:
|
170
129
|
- MIT
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module Accounts
|
2
|
-
class AdminAccountRepository
|
3
|
-
|
4
|
-
def create_account(user)
|
5
|
-
return unless user
|
6
|
-
return if user.accounts.admins.any?
|
7
|
-
|
8
|
-
account = ::Account.new(type_id: ::Dictionaries::AccountType::ADMIN)
|
9
|
-
admin = ::Accounts::Admin.new(account: account)
|
10
|
-
|
11
|
-
account.user = user
|
12
|
-
account.name = user.name.to_s
|
13
|
-
account.active = true
|
14
|
-
|
15
|
-
account.transaction do
|
16
|
-
account.save validate: false
|
17
|
-
admin.save validate: false
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def destroy_account(user)
|
22
|
-
return unless user
|
23
|
-
return unless user.accounts.admins.any?
|
24
|
-
|
25
|
-
account = user.accounts.admins.first
|
26
|
-
admin = account.admin
|
27
|
-
|
28
|
-
ActiveRecord::Base.transaction do
|
29
|
-
admin.destroy
|
30
|
-
account.destroy
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module Accounts
|
2
|
-
class CentralAgentAccountRepository
|
3
|
-
|
4
|
-
# todo-my: перевести в self.
|
5
|
-
def create_account(user)
|
6
|
-
return unless user
|
7
|
-
return if user.accounts.central_agents.any?
|
8
|
-
|
9
|
-
account = ::Account.new(type_id: ::Dictionaries::AccountType::CENTRAL_AGENT)
|
10
|
-
central = ::Accounts::CentralAgent.new(account: account)
|
11
|
-
|
12
|
-
account.user = user
|
13
|
-
account.name = user.name.to_s
|
14
|
-
account.active = true
|
15
|
-
user.is_notify = true
|
16
|
-
|
17
|
-
ActiveRecord::Base.transaction do
|
18
|
-
account.save
|
19
|
-
central.save
|
20
|
-
user.save
|
21
|
-
end
|
22
|
-
|
23
|
-
central
|
24
|
-
end
|
25
|
-
|
26
|
-
# todo-my: перевести в self.
|
27
|
-
def destroy_account(user)
|
28
|
-
return unless user
|
29
|
-
return unless user.accounts.central_agents.any?
|
30
|
-
|
31
|
-
account = user.accounts.central_agents.first
|
32
|
-
central = account.central_agent
|
33
|
-
|
34
|
-
ActiveRecord::Base.transaction do
|
35
|
-
central.destroy
|
36
|
-
account.destroy
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.fetch_or_create(user)
|
41
|
-
return unless user
|
42
|
-
return user.accounts.central_agents.first.central_agent if user.accounts.central_agents.any?
|
43
|
-
new.create_account(user)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
module Accounts
|
2
|
-
class ClientAccountRepository
|
3
|
-
|
4
|
-
def fetch_or_create(user)
|
5
|
-
return unless user
|
6
|
-
return user.accounts.clients.first.client if user.accounts.clients.any?
|
7
|
-
create_account(user)
|
8
|
-
end
|
9
|
-
|
10
|
-
def create_account(user)
|
11
|
-
return unless user
|
12
|
-
return if user.accounts.clients.any?
|
13
|
-
|
14
|
-
account = ::Account.new(type_id: ::Dictionaries::AccountType::CLIENT)
|
15
|
-
client = ::Accounts::Client.new(account: account)
|
16
|
-
|
17
|
-
account.user = user
|
18
|
-
account.name = user.name.to_s
|
19
|
-
account.active = true
|
20
|
-
|
21
|
-
account.transaction do
|
22
|
-
account.save validate: false
|
23
|
-
client.save validate: false
|
24
|
-
end
|
25
|
-
|
26
|
-
client
|
27
|
-
end
|
28
|
-
|
29
|
-
def destroy_account(user)
|
30
|
-
return unless user
|
31
|
-
return unless user.accounts.clients.any?
|
32
|
-
|
33
|
-
account = user.accounts.clients.first
|
34
|
-
client = account.client
|
35
|
-
|
36
|
-
ActiveRecord::Base.transaction do
|
37
|
-
client.destroy
|
38
|
-
account.destroy
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module Accounts
|
2
|
-
class ManagerAccountRepository
|
3
|
-
|
4
|
-
def create_account(user)
|
5
|
-
return unless user
|
6
|
-
return if user.accounts.managers.any?
|
7
|
-
|
8
|
-
account = ::Account.new(type_id: ::Dictionaries::AccountType::MANAGER)
|
9
|
-
manager = ::Accounts::Manager.new(account: account)
|
10
|
-
|
11
|
-
account.user = user
|
12
|
-
account.name = user.name.to_s
|
13
|
-
account.active = true
|
14
|
-
|
15
|
-
account.transaction do
|
16
|
-
account.save validate: false
|
17
|
-
manager.save validate: false
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def destroy_account(user)
|
22
|
-
return unless user
|
23
|
-
return unless user.accounts.managers.any?
|
24
|
-
|
25
|
-
account = user.accounts.managers.first
|
26
|
-
manager = account.manager
|
27
|
-
|
28
|
-
ActiveRecord::Base.transaction do
|
29
|
-
manager.destroy
|
30
|
-
account.destroy
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module Accounts
|
2
|
-
class ManagerGuestAccountRepository
|
3
|
-
|
4
|
-
def create_account(user)
|
5
|
-
return unless user
|
6
|
-
return if user.accounts.managers_guests.any?
|
7
|
-
|
8
|
-
account = ::Account.new(type_id: ::Dictionaries::AccountType::MANAGER_GUEST)
|
9
|
-
manager = ::Accounts::ManagerGuest.new(account: account)
|
10
|
-
|
11
|
-
account.user = user
|
12
|
-
account.name = user.name.to_s
|
13
|
-
account.active = true
|
14
|
-
|
15
|
-
account.transaction do
|
16
|
-
account.save validate: false
|
17
|
-
manager.save validate: false
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def destroy_account(user)
|
22
|
-
return unless user
|
23
|
-
return unless user.accounts.managers_guests.any?
|
24
|
-
|
25
|
-
account = user.accounts.managers_guests.first
|
26
|
-
manager = account.manager_guest
|
27
|
-
|
28
|
-
ActiveRecord::Base.transaction do
|
29
|
-
manager.destroy
|
30
|
-
account.destroy
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module Accounts
|
2
|
-
class ModeratorAccountRepository
|
3
|
-
|
4
|
-
def create_account(user)
|
5
|
-
return unless user
|
6
|
-
return if user.accounts.moderators.any?
|
7
|
-
|
8
|
-
account = ::Account.new(type_id: ::Dictionaries::AccountType::MODERATOR)
|
9
|
-
moderator = ::Accounts::Moderator.new(account: account)
|
10
|
-
|
11
|
-
account.user = user
|
12
|
-
account.name = user.name.to_s
|
13
|
-
account.active = true
|
14
|
-
|
15
|
-
account.transaction do
|
16
|
-
account.save validate: false
|
17
|
-
moderator.save validate: false
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def destroy_account(user)
|
22
|
-
return unless user
|
23
|
-
return unless user.accounts.moderators.any?
|
24
|
-
|
25
|
-
account = user.accounts.moderators.first
|
26
|
-
moderator = account.moderator
|
27
|
-
|
28
|
-
ActiveRecord::Base.transaction do
|
29
|
-
moderator.destroy
|
30
|
-
account.destroy
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
data/app/schemas/base.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require_relative '../../lib/dry/schema'
|
2
|
-
|
3
|
-
module Schemas
|
4
|
-
class Base
|
5
|
-
|
6
|
-
include Dry::Schema
|
7
|
-
|
8
|
-
def normalize_integer(value)
|
9
|
-
return nil if value.blank?
|
10
|
-
Integer(value.to_s.gsub(/\s/, '')) rescue value
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
def strip_string(value, empty_to_nil = true)
|
15
|
-
value = value.to_s.strip
|
16
|
-
value = nil if empty_to_nil && value.blank?
|
17
|
-
value
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
def to_date(value)
|
22
|
-
value.to_date rescue value
|
23
|
-
end
|
24
|
-
|
25
|
-
|
26
|
-
def clear_html(value)
|
27
|
-
Rails::Html::WhiteListSanitizer.new.sanitize(value)
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
def normalize_url(value)
|
32
|
-
return if value.blank?
|
33
|
-
value.to_s.strip.scan(/^https?:\/\//).present? ? value : sprintf('https://%s', value.to_s.strip)
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
def to_bool(value)
|
38
|
-
value.to_s.to_bool
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
def to_float(value)
|
43
|
-
return unless value.present?
|
44
|
-
BigDecimal.new(value.to_s.gsub(/\s/, '')) rescue value
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
def to_big_decimal(value)
|
49
|
-
return unless value.present?
|
50
|
-
BigDecimal.new(value.to_s.gsub(/\s/, '')) rescue value
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
def forced_array(value)
|
55
|
-
[value.present? ? value : nil].flatten.compact
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
|
-
def forced_hash(value)
|
60
|
-
value.blank? ? {} : value
|
61
|
-
end
|
62
|
-
|
63
|
-
|
64
|
-
def nullify_empty(value)
|
65
|
-
value.present? ? value : nil
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
end
|
@@ -1,235 +0,0 @@
|
|
1
|
-
require_relative 'base'
|
2
|
-
|
3
|
-
module Schemas
|
4
|
-
class BaseBoatSchema < ::Schemas::Base
|
5
|
-
def schema
|
6
|
-
result = {
|
7
|
-
properties: {
|
8
|
-
id: {
|
9
|
-
type: %i[null number],
|
10
|
-
cast: ->(value) { normalize_integer(value) }
|
11
|
-
},
|
12
|
-
name: {
|
13
|
-
type: [:null, :string],
|
14
|
-
cast: ->(value) { clear_html(strip_string(value)) },
|
15
|
-
rule: ->(parents) { rule_name(parents) }
|
16
|
-
},
|
17
|
-
boat_type_id: {
|
18
|
-
enum: [nil, -1] + Dicts::BoatType::ALL.collect(&:id),
|
19
|
-
cast: ->(value) { normalize_integer(value) },
|
20
|
-
rule: ->(parents) { rule_boat_type_id(parents) }
|
21
|
-
},
|
22
|
-
boat_model: {
|
23
|
-
type: %i[null string],
|
24
|
-
cast: ->(value) { clear_html(strip_string(value)) }
|
25
|
-
},
|
26
|
-
builder: {
|
27
|
-
type: %i[null string],
|
28
|
-
cast: ->(value) { clear_html(strip_string(value)) }
|
29
|
-
},
|
30
|
-
length: {
|
31
|
-
type: :hash,
|
32
|
-
required: %i[value length_id],
|
33
|
-
properties: {
|
34
|
-
value: {
|
35
|
-
type: %i[null number string],
|
36
|
-
cast: ->(value) { to_float(value) }
|
37
|
-
},
|
38
|
-
length_id: {
|
39
|
-
enum: Dicts::Length.all.collect(&:id),
|
40
|
-
cast: ->(value) { normalize_integer(value) }
|
41
|
-
}
|
42
|
-
}
|
43
|
-
},
|
44
|
-
crew_total: {
|
45
|
-
type: %i[null number],
|
46
|
-
cast: ->(value) { normalize_integer(value) }
|
47
|
-
},
|
48
|
-
guest_cabins: {
|
49
|
-
type: %i[null number],
|
50
|
-
cast: ->(value) { normalize_integer(value) }
|
51
|
-
},
|
52
|
-
guests_total: {
|
53
|
-
type: %i[null number],
|
54
|
-
cast: ->(value) { normalize_integer(value) }
|
55
|
-
},
|
56
|
-
maximum_guests_during_cruise: {
|
57
|
-
type: %i[null number],
|
58
|
-
cast: ->(value) { normalize_integer(value) },
|
59
|
-
rule: ->(parents) { rule_maximum_guests_during_cruise(parents) }
|
60
|
-
},
|
61
|
-
boat_locations_attributes: {
|
62
|
-
type: %i[null array],
|
63
|
-
items: {
|
64
|
-
type: :hash,
|
65
|
-
required: %i[latitude longitude address is_main _destroy],
|
66
|
-
cast: ->(value) do
|
67
|
-
value[:latitude] = to_big_decimal value[:latitude]
|
68
|
-
value[:longitude] = to_big_decimal value[:longitude]
|
69
|
-
value[:address] = strip_string value[:address]
|
70
|
-
value[:is_main] = to_bool value[:is_main]
|
71
|
-
value[:_destroy] = to_bool value[:_destroy]
|
72
|
-
|
73
|
-
value[:latitude].nil? || value[:longitude].nil? || !value[:address].present? ? nil : value
|
74
|
-
end
|
75
|
-
},
|
76
|
-
cast: ->(value) { forced_array(value) }
|
77
|
-
}
|
78
|
-
}
|
79
|
-
}
|
80
|
-
|
81
|
-
result[:properties][:rent_prices] = {
|
82
|
-
type: [:null, :array], # это первая версия, где я пробую разобраться с массивом объектов (версия покруче тут - app/getboat/schemas/base_boat_schema.rb - с помощью :items)
|
83
|
-
cast: ->(value) do
|
84
|
-
value.inject([]) do |res, el|
|
85
|
-
el[:_delete] = to_bool el[:_delete]
|
86
|
-
el[:currency] = normalize_integer el[:currency]
|
87
|
-
el[:discount] = to_float el[:discount]
|
88
|
-
el[:duration] = to_float el[:duration]
|
89
|
-
el[:season] = normalize_integer el[:season]
|
90
|
-
el[:uom] = normalize_integer el[:uom]
|
91
|
-
el[:value] = normalize_integer(el[:value].is_a?(String) ? el[:value].split(/[, ]/).join : el[:value])
|
92
|
-
res << el
|
93
|
-
res
|
94
|
-
end
|
95
|
-
end
|
96
|
-
}
|
97
|
-
|
98
|
-
result[:properties][:sale_price] = {
|
99
|
-
type: [:null, :hash],
|
100
|
-
properties: {
|
101
|
-
currency_id: {
|
102
|
-
enum: Dicts::Currency.all.collect(&:id),
|
103
|
-
cast: ->(value) { normalize_integer(value) }
|
104
|
-
},
|
105
|
-
value: {
|
106
|
-
type: %i[number null string],
|
107
|
-
cast: ->(value) do
|
108
|
-
val = value.is_a?(String) ? value.split(/[, ]/).join : value
|
109
|
-
normalize_integer val
|
110
|
-
end
|
111
|
-
},
|
112
|
-
discount: {
|
113
|
-
type: %i[number null string],
|
114
|
-
cast: ->(value) { to_float(value) }
|
115
|
-
},
|
116
|
-
}
|
117
|
-
}
|
118
|
-
|
119
|
-
result[:properties][:boat_photos_attributes] = {
|
120
|
-
type: [:null, :hash],
|
121
|
-
cast: ->(value) { nullify_empty(value) },
|
122
|
-
rule: ->(parents) { rule_boat_photos_attributes(parents)}
|
123
|
-
}
|
124
|
-
|
125
|
-
result
|
126
|
-
end
|
127
|
-
|
128
|
-
|
129
|
-
def rule_name(parents)
|
130
|
-
messages = {
|
131
|
-
present: I18n.t('errors.boat.name.blank'),
|
132
|
-
length_between: I18n.t('errors.boat.name.length_invalid', min: 2, max: 255)
|
133
|
-
}
|
134
|
-
rule(:name, parents, messages) { present? & length_between?(2..255) }
|
135
|
-
end
|
136
|
-
|
137
|
-
|
138
|
-
def rule_boat_type_id(parents)
|
139
|
-
messages = {
|
140
|
-
present: I18n.t('errors.boat.boat_type_id.blank'),
|
141
|
-
gt: I18n.t('errors.boat.boat_type_id.blank')
|
142
|
-
}
|
143
|
-
rule(:boat_type_id, parents, messages) { present? & gt?(0) }
|
144
|
-
end
|
145
|
-
|
146
|
-
|
147
|
-
def rule_maximum_guests_during_cruise(parents)
|
148
|
-
messages = {
|
149
|
-
present: I18n.t('errors.boat.maximum_guests_during_cruise.blank'),
|
150
|
-
gt: I18n.t('errors.boat.maximum_guests_during_cruise.blank')
|
151
|
-
}
|
152
|
-
rule(:maximum_guests_during_cruise, parents, messages) { present? & gt?(0) }
|
153
|
-
end
|
154
|
-
|
155
|
-
|
156
|
-
def rule_boat_photos_attributes(parents)
|
157
|
-
messages = { present: I18n.t('errors.boat.boat_photos_attributes.blank') }
|
158
|
-
rule(:boat_photos_attributes, parents, messages) { present? }
|
159
|
-
end
|
160
|
-
|
161
|
-
|
162
|
-
def validate_location
|
163
|
-
unless boat_locations_attributes
|
164
|
-
errors.add :boat_locations, I18n.t('errors.boat.boat_locations.blank')
|
165
|
-
return
|
166
|
-
end
|
167
|
-
|
168
|
-
bls = boat_locations_attributes.compact.select { |loc| !loc[:_destroy] }
|
169
|
-
mbls = bls.select { |loc| loc[:is_main] }
|
170
|
-
|
171
|
-
if bls.size.zero?
|
172
|
-
errors.add :boat_locations, I18n.t('errors.boat.boat_locations.blank')
|
173
|
-
return
|
174
|
-
end
|
175
|
-
|
176
|
-
if bls.size > 5
|
177
|
-
errors.add :boat_locations, I18n.t('errors.boat.boat_locations.limit', max: 5)
|
178
|
-
return
|
179
|
-
end
|
180
|
-
|
181
|
-
if mbls.size == 0
|
182
|
-
errors.add :boat_locations, I18n.t('errors.boat.boat_locations.is_main')
|
183
|
-
return
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
|
188
|
-
def validate_length
|
189
|
-
errors.add(:length_value, I18n.t('errors.boat.length.blank')) unless length[:value]&.nonzero?
|
190
|
-
end
|
191
|
-
|
192
|
-
|
193
|
-
def validate_crew_total
|
194
|
-
errors.add(:crew_total, I18n.t('errors.boat.crew_total.blank')) unless crew_total.present?
|
195
|
-
end
|
196
|
-
|
197
|
-
|
198
|
-
def validate_guests_total
|
199
|
-
errors.add(:guests_total, I18n.t('errors.boat.guests_total.blank')) unless guests_total.present?
|
200
|
-
end
|
201
|
-
|
202
|
-
|
203
|
-
def validate_guest_cabins
|
204
|
-
errors.add(:guest_cabins, I18n.t('errors.boat.guest_cabins.blank')) unless guest_cabins.present?
|
205
|
-
end
|
206
|
-
|
207
|
-
|
208
|
-
def validate_prices_and_rent_prices
|
209
|
-
rent_prices_present = rent_prices.present? && rent_prices.count { |price| price[:_delete] } < rent_prices.count
|
210
|
-
sale_price_present = sale_price.present? && sale_price[:value]&.>(0)
|
211
|
-
return if rent_prices_present && sale_price_present
|
212
|
-
|
213
|
-
if !(rent_prices_present || sale_price_present)
|
214
|
-
errors.add :rent_prices, I18n.t('errors.boat.prices.any')
|
215
|
-
errors.add :sale_price, I18n.t('errors.boat.prices.any')
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
|
220
|
-
def validate_rent_prices
|
221
|
-
return unless rent_prices.present?
|
222
|
-
|
223
|
-
rent_prices.each do |price|
|
224
|
-
if price[:value].nil? || price[:value].zero?
|
225
|
-
errors.add :rent_prices, I18n.t('errors.boat.rent_prices.invalid')
|
226
|
-
break
|
227
|
-
end
|
228
|
-
if price[:duration].nil? || price[:duration].zero?
|
229
|
-
errors.add :rent_prices, I18n.t('errors.boat.rent_prices.invalid_duration')
|
230
|
-
break
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|