From a899f65113b5e16247db7ab32ffaf8ff5f96dd32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Saracca?= Date: Mon, 11 Nov 2024 13:20:30 -0300 Subject: [PATCH] feat: update model and transformer --- src/collections/domain/dtos/CollectionDTO.ts | 14 ++--------- src/collections/domain/models/Collection.ts | 6 +++++ .../domain/models/CollectionContact.ts | 4 ++++ .../domain/models/CollectionType.ts | 11 +++++++++ .../transformers/CollectionPayload.ts | 9 ++++++++ .../transformers/collectionTransformers.ts | 23 ++++++++++++++++++- 6 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 src/collections/domain/models/CollectionContact.ts create mode 100644 src/collections/domain/models/CollectionType.ts diff --git a/src/collections/domain/dtos/CollectionDTO.ts b/src/collections/domain/dtos/CollectionDTO.ts index f732afea..b669ef6c 100644 --- a/src/collections/domain/dtos/CollectionDTO.ts +++ b/src/collections/domain/dtos/CollectionDTO.ts @@ -1,3 +1,5 @@ +import { CollectionType } from '../models/CollectionType' + export interface CollectionDTO { alias: string name: string @@ -15,15 +17,3 @@ export interface CollectionInputLevelDTO { include: boolean required: boolean } - -export enum CollectionType { - RESEARCHERS = 'RESEARCHERS', - RESEARCH_PROJECTS = 'RESEARCH_PROJECTS', - JOURNALS = 'JOURNALS', - ORGANIZATIONS_INSTITUTIONS = 'ORGANIZATIONS_INSTITUTIONS', - TEACHING_COURSES = 'TEACHING_COURSES', - UNCATEGORIZED = 'UNCATEGORIZED', - LABORATORY = 'LABORATORY', - RESEARCH_GROUP = 'RESEARCH_GROUP', - DEPARTMENT = 'DEPARTMENT' -} diff --git a/src/collections/domain/models/Collection.ts b/src/collections/domain/models/Collection.ts index 1cc1f1e4..9aeb1f2b 100644 --- a/src/collections/domain/models/Collection.ts +++ b/src/collections/domain/models/Collection.ts @@ -1,4 +1,6 @@ import { DvObjectOwnerNode } from '../../../core' +import { CollectionContact } from './CollectionContact' +import { CollectionType } from './CollectionType' export interface Collection { id: number @@ -9,6 +11,10 @@ export interface Collection { description?: string isPartOf: DvObjectOwnerNode inputLevels?: CollectionInputLevel[] + type: CollectionType + contacts?: CollectionContact[] + usesMetadataFieldsFromParent: boolean + usesBrowseSearchFacetsFromParent: boolean } export interface CollectionInputLevel { diff --git a/src/collections/domain/models/CollectionContact.ts b/src/collections/domain/models/CollectionContact.ts new file mode 100644 index 00000000..4264b9c0 --- /dev/null +++ b/src/collections/domain/models/CollectionContact.ts @@ -0,0 +1,4 @@ +export interface CollectionContact { + email: string + displayOrder: number +} diff --git a/src/collections/domain/models/CollectionType.ts b/src/collections/domain/models/CollectionType.ts new file mode 100644 index 00000000..2b587895 --- /dev/null +++ b/src/collections/domain/models/CollectionType.ts @@ -0,0 +1,11 @@ +export enum CollectionType { + RESEARCHERS = 'RESEARCHERS', + RESEARCH_PROJECTS = 'RESEARCH_PROJECTS', + JOURNALS = 'JOURNALS', + ORGANIZATIONS_INSTITUTIONS = 'ORGANIZATIONS_INSTITUTIONS', + TEACHING_COURSES = 'TEACHING_COURSES', + UNCATEGORIZED = 'UNCATEGORIZED', + LABORATORY = 'LABORATORY', + RESEARCH_GROUP = 'RESEARCH_GROUP', + DEPARTMENT = 'DEPARTMENT' +} diff --git a/src/collections/infra/repositories/transformers/CollectionPayload.ts b/src/collections/infra/repositories/transformers/CollectionPayload.ts index 4b63d715..afd34a6d 100644 --- a/src/collections/infra/repositories/transformers/CollectionPayload.ts +++ b/src/collections/infra/repositories/transformers/CollectionPayload.ts @@ -9,6 +9,10 @@ export interface CollectionPayload { description?: string isPartOf: OwnerNodePayload inputLevels?: CollectionInputLevelPayload[] + dataverseContacts?: CollectionContactPayload[] + dataverseType: string + usesMetadataFieldsFromParent: boolean + usesBrowseSearchFacetsFromParent: boolean } export interface CollectionInputLevelPayload { @@ -16,3 +20,8 @@ export interface CollectionInputLevelPayload { required: boolean include: boolean } + +export interface CollectionContactPayload { + contactEmail: string + displayOrder: number +} diff --git a/src/collections/infra/repositories/transformers/collectionTransformers.ts b/src/collections/infra/repositories/transformers/collectionTransformers.ts index 9c4afd79..aad601bc 100644 --- a/src/collections/infra/repositories/transformers/collectionTransformers.ts +++ b/src/collections/infra/repositories/transformers/collectionTransformers.ts @@ -1,6 +1,10 @@ import { Collection, CollectionInputLevel } from '../../../domain/models/Collection' import { AxiosResponse } from 'axios' -import { CollectionInputLevelPayload, CollectionPayload } from './CollectionPayload' +import { + CollectionContactPayload, + CollectionInputLevelPayload, + CollectionPayload +} from './CollectionPayload' import { transformPayloadToOwnerNode } from '../../../../core/infra/repositories/transformers/dvObjectOwnerNodeTransformer' import { transformHtmlToMarkdown } from '../../../../datasets/infra/repositories/transformers/datasetTransformers' import { CollectionFacet } from '../../../domain/models/CollectionFacet' @@ -15,6 +19,8 @@ import { transformFilePreviewPayloadToFilePreview } from '../../../../files/infr import { transformCollectionPreviewPayloadToCollectionPreview } from './collectionPreviewsTransformers' import { CollectionPreviewPayload } from './CollectionPreviewPayload' import { CollectionPreview } from '../../../domain/models/CollectionPreview' +import { CollectionContact } from '../../../domain/models/CollectionContact' +import { CollectionType } from '../../../domain/models/CollectionType' export const transformCollectionResponseToCollection = (response: AxiosResponse): Collection => { const collectionPayload = response.data.data @@ -39,6 +45,9 @@ const transformPayloadToCollection = (collectionPayload: CollectionPayload): Col name: collectionPayload.name, isReleased: collectionPayload.isReleased, affiliation: collectionPayload.affiliation, + type: collectionPayload.dataverseType as CollectionType, + usesMetadataFieldsFromParent: true, // collectionPayload.usesMetadataFieldsFromParent // TODO:ME - Remove hardcoded value once https://github.com/IQSS/dataverse/issues/11012 is done + usesBrowseSearchFacetsFromParent: true, // collectionPayload.usesBrowseSearchFacetsFromParent collectionPayload.usesMetadataFieldsFromParent // TODO:ME - Remove hardcoded value once https://github.com/IQSS/dataverse/issues/11012 is done ...(collectionPayload.description && { description: transformHtmlToMarkdown(collectionPayload.description) }), @@ -47,6 +56,9 @@ const transformPayloadToCollection = (collectionPayload: CollectionPayload): Col }), ...(collectionPayload.inputLevels && { inputLevels: transformInputLevelsPayloadToInputLevels(collectionPayload.inputLevels) + }), + ...(collectionPayload.dataverseContacts && { + contacts: transformContactsPayloadToContacts(collectionPayload.dataverseContacts) }) } return collectionModel @@ -90,3 +102,12 @@ export const transformCollectionItemsResponseToCollectionItemSubset = ( totalItemCount: responseDataPayload.total_count } } + +const transformContactsPayloadToContacts = ( + contactsPayload: CollectionContactPayload[] +): CollectionContact[] => { + return contactsPayload.map((contactPayload) => ({ + email: contactPayload.contactEmail, + displayOrder: contactPayload.displayOrder + })) +}