2017-12-12 03:21:12 +01:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const types = {
|
|
|
|
locale: 'string',
|
|
|
|
timezone: 'string',
|
|
|
|
transformReq: 'function',
|
|
|
|
transformReqBody: 'function',
|
|
|
|
transformJourneysQuery: 'function',
|
|
|
|
|
2018-03-13 03:37:25 +01:00
|
|
|
products: 'array',
|
2017-12-12 03:28:54 +01:00
|
|
|
|
2017-12-12 03:21:12 +01:00
|
|
|
parseDateTime: 'function',
|
|
|
|
parseDeparture: 'function',
|
2017-12-28 16:56:27 +01:00
|
|
|
parseJourneyLeg: 'function',
|
2017-12-12 03:21:12 +01:00
|
|
|
parseJourney: 'function',
|
|
|
|
parseLine: 'function',
|
|
|
|
parseStationName: 'function',
|
|
|
|
parseLocation: 'function',
|
|
|
|
parseMovement: 'function',
|
|
|
|
parseNearby: 'function',
|
|
|
|
parseOperator: 'function',
|
|
|
|
parseRemark: 'function',
|
|
|
|
parseStopover: 'function',
|
|
|
|
|
|
|
|
formatAddress: 'function',
|
|
|
|
formatCoord: 'function',
|
|
|
|
formatDate: 'function',
|
|
|
|
formatLocationFilter: 'function',
|
|
|
|
formatPoi: 'function',
|
|
|
|
formatStation: 'function',
|
|
|
|
formatTime: 'function',
|
|
|
|
formatLocation: 'function',
|
|
|
|
formatRectangle: 'function'
|
|
|
|
}
|
|
|
|
|
|
|
|
const validateProfile = (profile) => {
|
|
|
|
for (let key of Object.keys(types)) {
|
|
|
|
const type = types[key]
|
2018-03-13 03:37:25 +01:00
|
|
|
if (type === 'array') {
|
|
|
|
if (!Array.isArray(profile[key])) {
|
|
|
|
throw new Error(`profile.${key} must be an array.`)
|
|
|
|
}
|
|
|
|
} else if (type !== typeof profile[key]) {
|
2017-12-12 03:21:12 +01:00
|
|
|
throw new Error(`profile.${key} must be a ${type}.`)
|
|
|
|
}
|
2017-12-12 03:28:54 +01:00
|
|
|
if (type === 'object' && profile[key] === null) {
|
|
|
|
throw new Error(`profile.${key} must not be null.`)
|
|
|
|
}
|
2017-12-12 03:21:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = validateProfile
|