deep_unrest 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/deep_unrest/application_controller.rb +16 -7
- data/lib/deep_unrest/version.rb +1 -1
- data/lib/deep_unrest.rb +16 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae3d92d31f39fb9850caad832917df453a3d1c9b
|
4
|
+
data.tar.gz: e9d68cb90229eb52728e9889fcee1a0e02391b08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e3334ab48073acdfafd5958d876cadca7cae37e4a4d0a1845bcbc2f2d4dbfbb30894698c85ca14bb370d7c3c0aa0dd8c20d01611a8d0397df0ddacc2836d0b1
|
7
|
+
data.tar.gz: cefde02eb26d6e4bfd6dcb21ec4942e4edfc3c7fea2c0b278d5fb95902b102ea768c5b424d8d009b5ce9e724f6847f664f661ac4e451ca97899eff0b6e2db583
|
@@ -6,16 +6,25 @@ module DeepUnrest
|
|
6
6
|
{ current_user: current_user }
|
7
7
|
end
|
8
8
|
|
9
|
+
|
10
|
+
# multipart data will be an array-like hash
|
11
|
+
def format_data(data)
|
12
|
+
if data.respond_to? :values
|
13
|
+
data.values
|
14
|
+
else
|
15
|
+
data
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
9
19
|
def update
|
10
20
|
redirect = allowed_params[:redirect]
|
11
|
-
|
21
|
+
data = format_data(allowed_params[:data])
|
22
|
+
redirect_replace = DeepUnrest.perform_update(data,
|
12
23
|
current_user)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
render json: {}, status: 200
|
18
|
-
end
|
24
|
+
resp = {}
|
25
|
+
resp[:redirect] = redirect_replace.call(redirect) if redirect
|
26
|
+
response.headers.merge! update_auth_header
|
27
|
+
render json: resp, status: 200
|
19
28
|
rescue DeepUnrest::Unauthorized => err
|
20
29
|
render json: err.message, status: 403
|
21
30
|
rescue DeepUnrest::UnpermittedParams => err
|
data/lib/deep_unrest/version.rb
CHANGED
data/lib/deep_unrest.rb
CHANGED
@@ -384,6 +384,20 @@ module DeepUnrest
|
|
384
384
|
end
|
385
385
|
end
|
386
386
|
|
387
|
+
def self.format_error_keys(res, i)
|
388
|
+
record = res[:record]
|
389
|
+
errors = record&.errors&.messages
|
390
|
+
if errors
|
391
|
+
base_key = "#{record.class.to_s.underscore.pluralize}[#{i}]"
|
392
|
+
errors.keys.map do |attr|
|
393
|
+
if record.respond_to? attr
|
394
|
+
errors["#{base_key}.#{attr}".to_sym] = errors.delete(attr)
|
395
|
+
end
|
396
|
+
end
|
397
|
+
end
|
398
|
+
errors
|
399
|
+
end
|
400
|
+
|
387
401
|
def self.perform_update(params, user)
|
388
402
|
# identify requested scope(s)
|
389
403
|
scopes = collect_all_scopes(params)
|
@@ -401,10 +415,9 @@ module DeepUnrest
|
|
401
415
|
results = mutate(mutations, user).flatten
|
402
416
|
|
403
417
|
# check results for errors
|
404
|
-
errors = results.
|
418
|
+
errors = results.each_with_index
|
419
|
+
.map { |res, i| format_error_keys(res, i) }
|
405
420
|
.compact
|
406
|
-
.map(&:errors)
|
407
|
-
.map(&:messages)
|
408
421
|
.reject(&:empty?)
|
409
422
|
.compact
|
410
423
|
|