1
1
import 'core-js' ;
2
2
import * as lookups from './lookups.js' ;
3
3
import { updateCostAdditionalDetail , updateSummaryMeasurement , updateTariffRider , updateUsagePoint } from './objectUpdaters.js' ;
4
+ import { ensureArray } from './utilities.js' ;
4
5
function updateApplicationInformationContent ( content ) {
5
6
if ( content === undefined ) {
6
7
return ;
@@ -19,18 +20,14 @@ function updateApplicationInformationContent(content) {
19
20
content . thirdPartyApplicationUse_value =
20
21
lookups . thirdPartyApplicationUses [ content . thirdPartyApplicationUse ] ;
21
22
}
22
- if ( ! Array . isArray ( content . grant_types ) ) {
23
- content . grant_types = [ content . grant_types ] ;
24
- }
25
- if ( content . contacts !== undefined && ! Array . isArray ( content . contacts ) ) {
26
- content . contacts = [ content . contacts ] ;
27
- }
28
- if ( ! Array . isArray ( content . scope ) ) {
29
- content . scope = [ content . scope ] ;
30
- }
31
- content . grant_types_values = [ ] ;
32
- for ( const grantType of content . grant_types ) {
33
- content . grant_types_values . push ( lookups . grantTypes [ grantType ] ) ;
23
+ ensureArray ( content , 'contacts' ) ;
24
+ ensureArray ( content , 'scope' ) ;
25
+ if ( content . grant_types !== undefined ) {
26
+ ensureArray ( content , 'grant_types' ) ;
27
+ content . grant_types_values = [ ] ;
28
+ for ( const grantType of content . grant_types ) {
29
+ content . grant_types_values . push ( lookups . grantTypes [ grantType ] ) ;
30
+ }
34
31
}
35
32
content . response_types_value = lookups . responseTypes [ content . response_types ] ;
36
33
}
@@ -51,9 +48,7 @@ function updateBatchListContent(content) {
51
48
if ( content === undefined ) {
52
49
return ;
53
50
}
54
- if ( ! Array . isArray ( content . resources ) ) {
55
- content . resources = [ content . resources ] ;
56
- }
51
+ ensureArray ( content , 'resources' ) ;
57
52
}
58
53
function updateCustomerContent ( content ) {
59
54
if ( content === undefined ) {
@@ -68,9 +63,7 @@ function updateCustomerAccountContent(content) {
68
63
return ;
69
64
}
70
65
if ( content . notifications !== undefined ) {
71
- if ( ! Array . isArray ( content . notifications ) ) {
72
- content . notifications = [ content . notifications ] ;
73
- }
66
+ ensureArray ( content , 'notifications' ) ;
74
67
for ( const notification of content . notifications ) {
75
68
notification . methodKind_value =
76
69
lookups . notificationMethodKinds [ notification . methodKind ] ;
@@ -82,9 +75,7 @@ function updateCustomerAgreementContent(content) {
82
75
return ;
83
76
}
84
77
if ( content . DemandResponseProgram !== undefined ) {
85
- if ( ! Array . isArray ( content . DemandResponseProgram ) ) {
86
- content . DemandResponseProgram = [ content . DemandResponseProgram ] ;
87
- }
78
+ ensureArray ( content , 'DemandResponseProgram' ) ;
88
79
for ( const program of content . DemandResponseProgram ) {
89
80
if ( program . enrollmentStatus !== undefined ) {
90
81
program . enrollmentStatus_value =
@@ -94,10 +85,7 @@ function updateCustomerAgreementContent(content) {
94
85
updateSummaryMeasurement ( program . DRProgramNomination ) ;
95
86
}
96
87
}
97
- if ( content . PricingStructures !== undefined &&
98
- ! Array . isArray ( content . PricingStructures ) ) {
99
- content . PricingStructures = [ content . PricingStructures ] ;
100
- }
88
+ ensureArray ( content , 'PricingStructures' ) ;
101
89
if ( content . currency !== undefined ) {
102
90
content . currency_value = lookups . currencies [ content . currency ] ;
103
91
}
@@ -106,15 +94,10 @@ function updateIntervalBlockContent(content) {
106
94
if ( content === undefined ) {
107
95
return ;
108
96
}
109
- if ( content . IntervalReading !== undefined &&
110
- ! Array . isArray ( content . IntervalReading ) ) {
111
- content . IntervalReading = [ content . IntervalReading ] ;
112
- }
97
+ ensureArray ( content , 'IntervalReading' ) ;
113
98
for ( const reading of content . IntervalReading ?? [ ] ) {
114
99
if ( reading . ReadingQuality !== undefined ) {
115
- if ( ! Array . isArray ( reading . ReadingQuality ) ) {
116
- reading . ReadingQuality = [ reading . ReadingQuality ] ;
117
- }
100
+ ensureArray ( reading , 'ReadingQuality' ) ;
118
101
reading . ReadingQuality_values = [ ] ;
119
102
for ( const quality of reading . ReadingQuality ) {
120
103
reading . ReadingQuality_values . push ( lookups . readingQualities [ quality ] ) ;
@@ -127,9 +110,7 @@ function updateMeterContent(content) {
127
110
return ;
128
111
}
129
112
if ( content . MeterMultipliers !== undefined ) {
130
- if ( ! Array . isArray ( content . MeterMultipliers ) ) {
131
- content . MeterMultipliers = [ content . MeterMultipliers ] ;
132
- }
113
+ ensureArray ( content , 'MeterMultipliers' ) ;
133
114
for ( const multiplier of content . MeterMultipliers ) {
134
115
if ( multiplier . kind !== undefined ) {
135
116
multiplier . kind_value = lookups . meterMultiplierKinds [ multiplier . kind ] ;
@@ -186,14 +167,9 @@ function updateServiceLocationContent(content) {
186
167
if ( content === undefined ) {
187
168
return ;
188
169
}
189
- if ( content . positionPoints !== undefined &&
190
- ! Array . isArray ( content . positionPoints ) ) {
191
- content . positionPoints = [ content . positionPoints ] ;
192
- }
170
+ ensureArray ( content , 'positionPoints' ) ;
193
171
if ( content . UsagePoints !== undefined ) {
194
- if ( ! Array . isArray ( content . UsagePoints ) ) {
195
- content . UsagePoints = [ content . UsagePoints ] ;
196
- }
172
+ ensureArray ( content , 'UsagePoints' ) ;
197
173
for ( const usagePoint of content . UsagePoints ) {
198
174
updateUsagePoint ( usagePoint ) ;
199
175
}
@@ -224,11 +200,7 @@ function updateUsageSummaryContent(content) {
224
200
return ;
225
201
}
226
202
if ( content . costAdditionalDetailsLastPeriod !== undefined ) {
227
- if ( ! Array . isArray ( content . costAdditionalDetailsLastPeriod ) ) {
228
- content . costAdditionalDetailsLastPeriod = [
229
- content . costAdditionalDetailsLastPeriod
230
- ] ;
231
- }
203
+ ensureArray ( content , 'costAdditionalDetailsLastPeriod' ) ;
232
204
for ( const additionalDetail of content . costAdditionalDetailsLastPeriod ) {
233
205
updateCostAdditionalDetail ( additionalDetail ) ;
234
206
}
@@ -254,11 +226,7 @@ function updateUsageSummaryContent(content) {
254
226
content . commodity_value = lookups . commodities [ content . commodity ] ;
255
227
}
256
228
if ( content . tariffRiderRefs ?. tariffRiderRef !== undefined ) {
257
- if ( ! Array . isArray ( content . tariffRiderRefs . tariffRiderRef ) ) {
258
- content . tariffRiderRefs . tariffRiderRef = [
259
- content . tariffRiderRefs . tariffRiderRef
260
- ] ;
261
- }
229
+ ensureArray ( content . tariffRiderRefs , 'tariffRiderRef' ) ;
262
230
for ( const tariffRider of content . tariffRiderRefs . tariffRiderRef ) {
263
231
updateTariffRider ( tariffRider ) ;
264
232
}
0 commit comments