@@ -67,42 +67,13 @@ export class CollectionsRepository extends ApiRepository implements ICollections
67
67
collectionDTO : CollectionDTO ,
68
68
parentCollectionId : number | string = ROOT_COLLECTION_ALIAS
69
69
) : Promise < number > {
70
- const dataverseContacts : NewCollectionContactRequestPayload [ ] = collectionDTO . contacts . map (
71
- ( contact ) => ( {
72
- contactEmail : contact
73
- } )
74
- )
75
-
76
- const inputLevelsRequestBody : NewCollectionInputLevelRequestPayload [ ] =
77
- collectionDTO . inputLevels ?. map ( ( inputLevel ) => ( {
78
- datasetFieldTypeName : inputLevel . datasetFieldName ,
79
- include : inputLevel . include ,
80
- required : inputLevel . required
81
- } ) )
82
-
83
- const requestBody : NewCollectionRequestPayload = {
84
- alias : collectionDTO . alias ,
85
- name : collectionDTO . name ,
86
- dataverseContacts : dataverseContacts ,
87
- dataverseType : collectionDTO . type ,
88
- ...( collectionDTO . description && {
89
- description : collectionDTO . description
90
- } ) ,
91
- ...( collectionDTO . affiliation && {
92
- affiliation : collectionDTO . affiliation
93
- } ) ,
94
- metadataBlocks : {
95
- metadataBlockNames : collectionDTO . metadataBlockNames ,
96
- facetIds : collectionDTO . facetIds ,
97
- inputLevels : inputLevelsRequestBody
98
- }
99
- }
70
+ const requestBody = this . createCreateOrUpdateRequestBody ( collectionDTO ) ;
100
71
101
72
return this . doPost ( `/${ this . collectionsResourceName } /${ parentCollectionId } ` , requestBody )
102
73
. then ( ( response ) => response . data . data . id )
103
74
. catch ( ( error ) => {
104
- throw error
105
- } )
75
+ throw error ;
76
+ } ) ;
106
77
}
107
78
108
79
public async getCollectionFacets (
@@ -189,42 +160,40 @@ export class CollectionsRepository extends ApiRepository implements ICollections
189
160
collectionIdOrAlias : string | number ,
190
161
updatedCollection : CollectionDTO
191
162
) : Promise < void > {
192
- const dataverseContacts : NewCollectionContactRequestPayload [ ] = updatedCollection . contacts . map (
193
- ( contact ) => ( {
194
- contactEmail : contact
195
- } )
196
- )
163
+ const requestBody = this . createCreateOrUpdateRequestBody ( updatedCollection ) ;
164
+
165
+ return this . doPut ( `/${ this . collectionsResourceName } /${ collectionIdOrAlias } ` , requestBody )
166
+ . then ( ( ) => undefined )
167
+ . catch ( ( error ) => {
168
+ throw error ;
169
+ } ) ;
170
+ }
171
+
172
+ private createCreateOrUpdateRequestBody ( collectionDTO : CollectionDTO ) : NewCollectionRequestPayload {
173
+ const dataverseContacts : NewCollectionContactRequestPayload [ ] = collectionDTO . contacts . map ( ( contact ) => ( {
174
+ contactEmail : contact
175
+ } ) ) ;
197
176
198
177
const inputLevelsRequestBody : NewCollectionInputLevelRequestPayload [ ] =
199
- updatedCollection . inputLevels ?. map ( ( inputLevel ) => ( {
178
+ collectionDTO . inputLevels ?. map ( ( inputLevel ) => ( {
200
179
datasetFieldTypeName : inputLevel . datasetFieldName ,
201
180
include : inputLevel . include ,
202
181
required : inputLevel . required
203
- } ) )
182
+ } ) ) ;
204
183
205
- const requestBody : NewCollectionRequestPayload = {
206
- alias : updatedCollection . alias ,
207
- name : updatedCollection . name ,
184
+ return {
185
+ alias : collectionDTO . alias ,
186
+ name : collectionDTO . name ,
208
187
dataverseContacts : dataverseContacts ,
209
- dataverseType : updatedCollection . type ,
210
- ...( updatedCollection . description && {
211
- description : updatedCollection . description
212
- } ) ,
213
- ...( updatedCollection . affiliation && {
214
- affiliation : updatedCollection . affiliation
215
- } ) ,
188
+ dataverseType : collectionDTO . type ,
189
+ ...( collectionDTO . description && { description : collectionDTO . description } ) ,
190
+ ...( collectionDTO . affiliation && { affiliation : collectionDTO . affiliation } ) ,
216
191
metadataBlocks : {
217
- metadataBlockNames : updatedCollection . metadataBlockNames ,
218
- facetIds : updatedCollection . facetIds ,
192
+ metadataBlockNames : collectionDTO . metadataBlockNames ,
193
+ facetIds : collectionDTO . facetIds ,
219
194
inputLevels : inputLevelsRequestBody
220
195
}
221
- }
222
-
223
- return this . doPut ( `/${ this . collectionsResourceName } /${ collectionIdOrAlias } ` , requestBody )
224
- . then ( ( ) => undefined )
225
- . catch ( ( error ) => {
226
- throw error
227
- } )
196
+ } ;
228
197
}
229
198
230
199
private applyCollectionSearchCriteriaToQueryParams (
0 commit comments