@@ -67,42 +67,13 @@ export class CollectionsRepository extends ApiRepository implements ICollections
6767 collectionDTO : CollectionDTO ,
6868 parentCollectionId : number | string = ROOT_COLLECTION_ALIAS
6969 ) : 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 ) ;
10071
10172 return this . doPost ( `/${ this . collectionsResourceName } /${ parentCollectionId } ` , requestBody )
10273 . then ( ( response ) => response . data . data . id )
10374 . catch ( ( error ) => {
104- throw error
105- } )
75+ throw error ;
76+ } ) ;
10677 }
10778
10879 public async getCollectionFacets (
@@ -189,42 +160,40 @@ export class CollectionsRepository extends ApiRepository implements ICollections
189160 collectionIdOrAlias : string | number ,
190161 updatedCollection : CollectionDTO
191162 ) : 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+ } ) ) ;
197176
198177 const inputLevelsRequestBody : NewCollectionInputLevelRequestPayload [ ] =
199- updatedCollection . inputLevels ?. map ( ( inputLevel ) => ( {
178+ collectionDTO . inputLevels ?. map ( ( inputLevel ) => ( {
200179 datasetFieldTypeName : inputLevel . datasetFieldName ,
201180 include : inputLevel . include ,
202181 required : inputLevel . required
203- } ) )
182+ } ) ) ;
204183
205- const requestBody : NewCollectionRequestPayload = {
206- alias : updatedCollection . alias ,
207- name : updatedCollection . name ,
184+ return {
185+ alias : collectionDTO . alias ,
186+ name : collectionDTO . name ,
208187 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 } ) ,
216191 metadataBlocks : {
217- metadataBlockNames : updatedCollection . metadataBlockNames ,
218- facetIds : updatedCollection . facetIds ,
192+ metadataBlockNames : collectionDTO . metadataBlockNames ,
193+ facetIds : collectionDTO . facetIds ,
219194 inputLevels : inputLevelsRequestBody
220195 }
221- }
222-
223- return this . doPut ( `/${ this . collectionsResourceName } /${ collectionIdOrAlias } ` , requestBody )
224- . then ( ( ) => undefined )
225- . catch ( ( error ) => {
226- throw error
227- } )
196+ } ;
228197 }
229198
230199 private applyCollectionSearchCriteriaToQueryParams (
0 commit comments