-
Notifications
You must be signed in to change notification settings - Fork 8
/
utils.ts
73 lines (62 loc) · 2.08 KB
/
utils.ts
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
// SPDX-FileCopyrightText: NOI Techpark <digital@noi.bz.it>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
import { RecordId } from './types';
import { computeTableLocation } from '../../domain/datasets/location/datasetViewLocation';
import { TourismMetaData } from '../metaDataConfig/tourism/types';
export const computeRecordId = (
domain: string | undefined,
record?: any
): RecordId => {
if (record == null || Array.isArray(record)) {
return undefined;
}
switch (domain) {
case 'tourism': {
return idToString(record.id ?? record.Id);
}
case 'mobility': {
// scode is the station code, evuuid is the event uuid, id is the generic id
return idToString(record.scode ?? record.evuuid ?? record.id);
}
default: {
return idToString(record.id);
}
}
};
const idToString = (id: TourismMetaData) =>
id == null ? undefined : id.toString();
export const getTableLocationFromDataset = (dataset: TourismMetaData) => {
if (dataset == null || dataset.baseUrl == null) {
return;
}
const domain = translateApiTypeToDomain(dataset);
const { pathSegments, apiFilter } = dataset;
return computeTableLocation(domain, pathSegments, apiFilter);
};
export const getApiDomain = (dataset: TourismMetaData) => {
if (dataset == null || dataset.baseUrl == null) {
return;
}
return translateApiTypeToDomain(dataset);
};
const translateApiTypeToDomain = (dataset: TourismMetaData) => {
if (dataset.apiType) {
// Add here all apiTypes
switch (dataset.apiType) {
case 'content':
return 'tourism';
case 'timeseries':
return 'mobility';
default:
return dataset.apiType;
}
} else {
// Id no apiType is present lets use the dirty hack ;)
// TODO: this is a very dirty hack to determine if the domain is the tourism or mobility
// domain. A better solution would be to have a domain property in the dataset metadata,
// because that way we can support other domains without code changes.
if (dataset.baseUrl.includes('tourism')) return 'tourism';
else return 'mobility';
}
};