Skip to content

Commit bbe16ba

Browse files
committed
refactor: remove AllowedDatasetType and replace with DatasetType, update related interfaces and transformers
1 parent 97e2a55 commit bbe16ba

7 files changed

Lines changed: 44 additions & 39 deletions

File tree

mini.js

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,43 @@
11
const { ApiConfig, getDataset, getDatasetStorageDriver, getCollection } = require('./dist')
22

33
function requiredEnv(name) {
4-
const value = process.env[name]
5-
if (!value) {
6-
throw new Error(`Missing required environment variable: ${name}`)
7-
}
8-
return value
4+
const value = process.env[name]
5+
if (!value) {
6+
throw new Error(`Missing required environment variable: ${name}`)
7+
}
8+
return value
99
}
1010

1111
async function main() {
12-
const DATAVERSE_API_URL = "http://localhost:8080/api"
13-
const DATAVERSE_API_KEY = "e79d640d-0cc1-465d-b5a1-1bc134d562e8"
14-
const DATASET_ID = "reviews"
15-
const DATASET_VERSION = process.env.DATASET_VERSION || 'latest'
12+
const DATAVERSE_API_URL = 'http://localhost:8080/api'
13+
const DATAVERSE_API_KEY = 'e79d640d-0cc1-465d-b5a1-1bc134d562e8'
14+
const DATASET_ID = 'reviews'
15+
const DATASET_VERSION = process.env.DATASET_VERSION || 'latest'
1616

17-
ApiConfig.init("http://localhost:8080/api", ApiConfig.API_KEY, "e79d640d-0cc1-465d-b5a1-1bc134d562e8");
17+
ApiConfig.init(
18+
'http://localhost:8080/api',
19+
ApiConfig.API_KEY,
20+
'e79d640d-0cc1-465d-b5a1-1bc134d562e8'
21+
)
1822

19-
20-
getCollection.execute("reviews")
21-
.then(collection => {
22-
console.log('Collection allowed dataset types:', collection.allowedDatasetTypes);
23-
console.log('Collection:', collection);
24-
})
25-
.catch(error => {
26-
console.error('Error fetching collection:', {
27-
name: error?.name,
28-
message: error?.message,
29-
cause: error?.cause,
30-
stack: error?.stack,
31-
});
32-
});
23+
getCollection
24+
.execute('reviews')
25+
.then((collection) => {
26+
console.log('Collection allowed dataset types:', collection.allowedDatasetTypes)
27+
console.log('Collection:', collection)
28+
})
29+
.catch((error) => {
30+
console.error('Error fetching collection:', {
31+
name: error?.name,
32+
message: error?.message,
33+
cause: error?.cause,
34+
stack: error?.stack
35+
})
36+
})
3337
}
3438

3539
main().catch((error) => {
36-
console.error('Execution failed:')
37-
console.error(error?.message || error)
38-
process.exit(1)
40+
console.error('Execution failed:')
41+
console.error(error?.message || error)
42+
process.exit(1)
3943
})

src/collections/domain/models/AllowedDatasetType.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/collections/domain/models/Collection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DvObjectOwnerNode } from '../../../core'
22
import { CollectionContact } from './CollectionContact'
33
import { CollectionType } from './CollectionType'
4-
import { AllowedDatasetType } from './AllowedDatasetType'
4+
import { DatasetType } from '../../../datasets'
55

66
export interface Collection {
77
id: number
@@ -14,7 +14,7 @@ export interface Collection {
1414
inputLevels?: CollectionInputLevel[]
1515
type: CollectionType
1616
contacts?: CollectionContact[]
17-
allowedDatasetTypes?: AllowedDatasetType[]
17+
allowedDatasetTypes?: DatasetType[]
1818
isMetadataBlockRoot: boolean
1919
isFacetRoot: boolean
2020
childCount: number

src/collections/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,3 @@ export { CollectionSearchCriteria } from './domain/models/CollectionSearchCriter
6666
export { FeaturedItem } from './domain/models/FeaturedItem'
6767
export { FeaturedItemsDTO } from './domain/dtos/FeaturedItemsDTO'
6868
export { CollectionSummary } from './domain/models/CollectionSummary'
69-
export { AllowedDatasetType } from './domain/models/AllowedDatasetType'

src/collections/infra/repositories/transformers/CollectionPayload.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ export interface CollectionContactPayload {
2929
}
3030

3131
export interface AllowedDatasetTypePayload {
32+
id: number
3233
name: string
3334
displayName: string
3435
description?: string
36+
linkedMetadataBlocks?: string[]
37+
availableLicenses?: string[]
3538
}

src/collections/infra/repositories/transformers/collectionTransformers.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
CollectionItemSubset,
1515
CountPerObjectType
1616
} from '../../../domain/models/CollectionItemSubset'
17-
import { DatasetPreview } from '../../../../datasets'
17+
import { DatasetPreview, DatasetType } from '../../../../datasets'
1818
import { FilePreview } from '../../../../files'
1919
import { DatasetPreviewPayload } from '../../../../datasets/infra/repositories/transformers/DatasetPreviewPayload'
2020
import { FilePreviewPayload } from '../../../../files/infra/repositories/transformers/FilePreviewPayload'
@@ -46,7 +46,6 @@ import {
4646
} from '../../../domain/models/MyDataCollectionItemSubset'
4747
import { PublicationStatus } from '../../../../core/domain/models/PublicationStatus'
4848
import { CollectionLinks } from '../../../domain/models/CollectionLinks'
49-
import { AllowedDatasetType } from '../../../domain/models/AllowedDatasetType'
5049

5150
export const transformCollectionResponseToCollection = (response: AxiosResponse): Collection => {
5251
const collectionPayload = response.data.data
@@ -262,10 +261,13 @@ const transformContactsPayloadToContacts = (
262261

263262
const transformAllowedDatasetTypesPayloadToAllowedDatasetTypes = (
264263
allowedDatasetTypesPayload: AllowedDatasetTypePayload[]
265-
): AllowedDatasetType[] => {
264+
): DatasetType[] => {
266265
return allowedDatasetTypesPayload.map((allowedDatasetType) => ({
266+
id: allowedDatasetType.id,
267267
name: allowedDatasetType.name,
268268
displayName: allowedDatasetType.displayName,
269-
description: allowedDatasetType.description
269+
description: allowedDatasetType.description,
270+
linkedMetadataBlocks: allowedDatasetType.linkedMetadataBlocks,
271+
availableLicenses: allowedDatasetType.availableLicenses
270272
}))
271273
}

test/testHelpers/collections/collectionHelper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const createCollectionModel = (): Collection => {
4747
],
4848
allowedDatasetTypes: [
4949
{
50+
id: 1,
5051
name: 'review',
5152
displayName: 'Review',
5253
description: 'A review of a dataset compiled by the expert community.'
@@ -84,6 +85,7 @@ export const createCollectionPayload = (): CollectionPayload => {
8485
],
8586
allowedDatasetTypes: [
8687
{
88+
id: 1,
8789
name: 'review',
8890
displayName: 'Review',
8991
description: 'A review of a dataset compiled by the expert community.'

0 commit comments

Comments
 (0)