@@ -38,6 +38,8 @@ import { ApiConstants } from '../../../core/infra/repositories/ApiConstants'
3838import { PublicationStatus } from '../../../core/domain/models/PublicationStatus'
3939import { ReadError } from '../../../core/domain/repositories/ReadError'
4040import { CollectionLinks } from '../../domain/models/CollectionLinks'
41+ import { CollectionSummary } from '../../domain/models/CollectionSummary'
42+ import { LinkingObjectType } from '../../domain/useCases/GetCollectionsForLinking'
4143
4244export interface NewCollectionRequestPayload {
4345 alias : string
@@ -93,7 +95,6 @@ export enum GetMyDataCollectionItemsQueryParams {
9395
9496export class CollectionsRepository extends ApiRepository implements ICollectionsRepository {
9597 private readonly collectionsResourceName : string = 'dataverses'
96-
9798 public async getCollection (
9899 collectionIdOrAlias : number | string = ROOT_COLLECTION_ID
99100 ) : Promise < Collection > {
@@ -485,4 +486,41 @@ export class CollectionsRepository extends ApiRepository implements ICollections
485486 throw error
486487 } )
487488 }
489+
490+ public async getCollectionsForLinking (
491+ objectType : LinkingObjectType ,
492+ id : number | string ,
493+ searchTerm : string
494+ ) : Promise < CollectionSummary [ ] > {
495+ let path : string
496+ const queryParams = new URLSearchParams ( )
497+ if ( objectType === 'collection' ) {
498+ path = `/${ this . collectionsResourceName } /${ id } /dataverse/linkingDataverses`
499+ } else {
500+ path = `/${ this . collectionsResourceName } /:persistentId/dataset/linkingDataverses`
501+ queryParams . set ( 'persistentId' , String ( id ) )
502+ }
503+
504+ if ( searchTerm ) {
505+ queryParams . set ( 'searchTerm' , searchTerm )
506+ }
507+
508+ return this . doGet ( path , true , queryParams )
509+ . then ( ( response ) => {
510+ const payload = response . data . data as {
511+ id : number
512+ alias : string
513+ name : string
514+ } [ ]
515+
516+ return payload . map ( ( item ) => ( {
517+ id : item . id ,
518+ alias : item . alias ,
519+ displayName : item . name
520+ } ) )
521+ } )
522+ . catch ( ( error ) => {
523+ throw error
524+ } )
525+ }
488526}
0 commit comments