-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDataverseInfoRepository.ts
More file actions
91 lines (84 loc) · 3.06 KB
/
DataverseInfoRepository.ts
File metadata and controls
91 lines (84 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { ApiRepository } from '../../../core/infra/repositories/ApiRepository'
import { IDataverseInfoRepository } from '../../domain/repositories/IDataverseInfoRepository'
import { DataverseVersion } from '../../domain/models/DataverseVersion'
import { AxiosResponse } from 'axios'
import { DatasetMetadataExportFormats } from '../../domain/models/DatasetMetadataExportFormats'
export class DataverseInfoRepository extends ApiRepository implements IDataverseInfoRepository {
private readonly infoResourceName: string = 'info'
public async getDataverseVersion(): Promise<DataverseVersion> {
return this.doGet(this.buildApiEndpoint(this.infoResourceName, `version`))
.then((response) => this.getVersionFromResponse(response))
.catch((error) => {
throw error
})
}
public async getZipDownloadLimit(): Promise<number> {
return this.doGet(this.buildApiEndpoint(this.infoResourceName, `zipDownloadLimit`))
.then((response) => parseInt(response.data.data))
.catch((error) => {
throw error
})
}
public async getMaxEmbargoDurationInMonths(): Promise<number> {
return this.doGet(
this.buildApiEndpoint(this.infoResourceName, `settings/:MaxEmbargoDurationInMonths`)
)
.then((response) => parseInt(response.data.data.message))
.catch((error) => {
throw error
})
}
private getVersionFromResponse(response: AxiosResponse): DataverseVersion {
const responseData = response.data.data
return {
number: responseData.version,
build: responseData.build
}
}
public async getApplicationTermsOfUse(lang?: string): Promise<string> {
return this.doGet(
this.buildApiEndpoint(this.infoResourceName, `applicationTermsOfUse`),
false,
{
...(lang ? { lang } : {})
}
)
.then((response: AxiosResponse<{ data: { message: string } }>) => {
return response.data.data.message
})
.catch((error) => {
throw error
})
}
public async getAvailableDatasetMetadataExportFormats(): Promise<DatasetMetadataExportFormats> {
return this.doGet(this.buildApiEndpoint(this.infoResourceName, `exportFormats`))
.then((response: AxiosResponse<{ data: DatasetMetadataExportFormats }>) => {
return response.data.data
})
.catch((error) => {
throw error
})
}
public async getDatasetPublishPopupCustomText(): Promise<string> {
return this.doGet(
this.buildApiEndpoint(this.infoResourceName, `settings/:DatasetPublishPopupCustomText`)
)
.then((response: AxiosResponse<{ data: { message: string } }>) => {
return response.data.data.message
})
.catch((error) => {
throw error
})
}
public async getPublishDatasetDisclaimerText(): Promise<string> {
return this.doGet(
this.buildApiEndpoint(this.infoResourceName, `settings/:PublishDatasetDisclaimerText`)
)
.then((response: AxiosResponse<{ data: { message: string } }>) => {
return response.data.data.message
})
.catch((error) => {
throw error
})
}
}