Skip to content

Commit

Permalink
feat: update model and transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
g-saracca committed Nov 11, 2024
1 parent 67d3b0e commit a899f65
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 13 deletions.
14 changes: 2 additions & 12 deletions src/collections/domain/dtos/CollectionDTO.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { CollectionType } from '../models/CollectionType'

export interface CollectionDTO {
alias: string
name: string
Expand All @@ -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'
}
6 changes: 6 additions & 0 deletions src/collections/domain/models/Collection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { DvObjectOwnerNode } from '../../../core'
import { CollectionContact } from './CollectionContact'
import { CollectionType } from './CollectionType'

export interface Collection {
id: number
Expand All @@ -9,6 +11,10 @@ export interface Collection {
description?: string
isPartOf: DvObjectOwnerNode
inputLevels?: CollectionInputLevel[]
type: CollectionType
contacts?: CollectionContact[]
usesMetadataFieldsFromParent: boolean
usesBrowseSearchFacetsFromParent: boolean
}

export interface CollectionInputLevel {
Expand Down
4 changes: 4 additions & 0 deletions src/collections/domain/models/CollectionContact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface CollectionContact {
email: string
displayOrder: number
}
11 changes: 11 additions & 0 deletions src/collections/domain/models/CollectionType.ts
Original file line number Diff line number Diff line change
@@ -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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@ export interface CollectionPayload {
description?: string
isPartOf: OwnerNodePayload
inputLevels?: CollectionInputLevelPayload[]
dataverseContacts?: CollectionContactPayload[]
dataverseType: string
usesMetadataFieldsFromParent: boolean
usesBrowseSearchFacetsFromParent: boolean
}

export interface CollectionInputLevelPayload {
datasetFieldTypeName: string
required: boolean
include: boolean
}

export interface CollectionContactPayload {
contactEmail: string
displayOrder: number
}
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand All @@ -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)
}),
Expand All @@ -47,6 +56,9 @@ const transformPayloadToCollection = (collectionPayload: CollectionPayload): Col
}),
...(collectionPayload.inputLevels && {
inputLevels: transformInputLevelsPayloadToInputLevels(collectionPayload.inputLevels)
}),
...(collectionPayload.dataverseContacts && {
contacts: transformContactsPayloadToContacts(collectionPayload.dataverseContacts)
})
}
return collectionModel
Expand Down Expand Up @@ -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
}))
}

0 comments on commit a899f65

Please sign in to comment.