@@ -41,13 +41,15 @@ import { ReviewActionPayloadJsonApi } from '../models/review-action/review-actio
4141import { SetTotalSubmissions } from '../stores/collections/collections.actions' ;
4242
4343import { JsonApiService } from './json-api.service' ;
44+ import { MetadataService } from './metadata.service' ;
4445
4546@Injectable ( {
4647 providedIn : 'root' ,
4748} )
4849export class CollectionsService {
4950 private readonly jsonApiService = inject ( JsonApiService ) ;
5051 private readonly environment = inject ( ENVIRONMENT ) ;
52+ private readonly metadataService = inject ( MetadataService ) ;
5153
5254 get apiUrl ( ) {
5355 return `${ this . environment . apiDomainUrl } /v2` ;
@@ -56,11 +58,22 @@ export class CollectionsService {
5658 private actions = createDispatchMap ( { setTotalSubmissions : SetTotalSubmissions } ) ;
5759
5860 getCollectionProvider ( collectionName : string ) : Observable < CollectionProvider > {
59- const url = `${ this . apiUrl } /providers/collections/${ collectionName } /?embed=brand,required_metadata_template ` ;
61+ const url = `${ this . apiUrl } /providers/collections/${ collectionName } /?embed=brand` ;
6062
61- return this . jsonApiService
62- . get < JsonApiResponse < CollectionProviderResponseJsonApi , null > > ( url )
63- . pipe ( map ( ( response ) => CollectionsMapper . fromGetCollectionProviderResponse ( response . data ) ) ) ;
63+ return this . jsonApiService . get < JsonApiResponse < CollectionProviderResponseJsonApi , null > > ( url ) . pipe (
64+ switchMap ( ( response ) => {
65+ const provider = CollectionsMapper . fromGetCollectionProviderResponse ( response . data ) ;
66+ const templateId = response . data . relationships . required_metadata_template ?. data ?. id ;
67+
68+ if ( ! templateId ) {
69+ return of ( provider ) ;
70+ }
71+
72+ return this . metadataService
73+ . getCedarMetadataTemplateDetail ( templateId )
74+ . pipe ( map ( ( template ) => ( { ...provider , requiredMetadataTemplate : template } ) ) ) ;
75+ } )
76+ ) ;
6477 }
6578
6679 getCollectionDetails ( collectionId : string ) : Observable < CollectionDetails > {
0 commit comments