screwdriver-api 8.0.191 → 8.0.192

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screwdriver-api",
3
- "version": "8.0.191",
3
+ "version": "8.0.192",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -65,21 +65,16 @@ module.exports = () => ({
65
65
  throw boom.conflict(`Token ${match.name} already exists`);
66
66
  }
67
67
 
68
- let payloadOptions;
69
-
70
- if (request.payload && request.payload.options) {
71
- payloadOptions = request.payload.options;
72
- }
73
-
74
68
  Object.keys(request.payload).forEach(key => {
75
69
  if (key === 'options') {
76
- const hasResourceUpdates =
77
- payloadOptions.resources && Object.keys(payloadOptions.resources).length > 0;
70
+ const payloadOptions = request.payload.options || {};
71
+ const tokenOptions = token.options || {};
72
+ const hasResourceUpdates = Object.keys(payloadOptions.resources || {}).length > 0;
78
73
 
79
74
  token.options = {
80
- ...token.options,
75
+ ...tokenOptions,
81
76
  ...payloadOptions,
82
- resources: hasResourceUpdates ? payloadOptions.resources : token.options.resources
77
+ resources: hasResourceUpdates ? payloadOptions.resources : tokenOptions.resources || {}
83
78
  };
84
79
  } else {
85
80
  token[key] = request.payload[key];
@@ -50,21 +50,18 @@ module.exports = () => ({
50
50
  throw boom.conflict(`Token with name ${match.name} already exists`);
51
51
  }
52
52
 
53
- let payloadOptions;
54
-
55
- if (request.payload && request.payload.options) {
56
- payloadOptions = request.payload.options;
57
- }
58
-
59
53
  Object.keys(request.payload).forEach(key => {
60
54
  if (key === 'options') {
61
- const hasResourceUpdates =
62
- payloadOptions.resources && Object.keys(payloadOptions.resources).length > 0;
55
+ const payloadOptions = request.payload.options || {};
56
+ const tokenOptions = token.options || {};
57
+ const hasResourceUpdates = Object.keys(payloadOptions.resources || {}).length > 0;
63
58
 
64
59
  token.options = {
65
- ...token.options,
60
+ ...tokenOptions,
66
61
  ...payloadOptions,
67
- resources: hasResourceUpdates ? payloadOptions.resources : token.options.resources
62
+ resources: hasResourceUpdates
63
+ ? payloadOptions.resources
64
+ : tokenOptions.resources || {}
68
65
  };
69
66
  } else {
70
67
  token[key] = request.payload[key];