fix profile and profile validation 🐛

This commit is contained in:
Jannis R 2018-03-13 03:37:25 +01:00
parent a10e9487bd
commit 551d2b8215
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
2 changed files with 7 additions and 2 deletions

View file

@ -7,7 +7,7 @@ const types = {
transformReqBody: 'function',
transformJourneysQuery: 'function',
products: 'object',
products: 'array',
parseDateTime: 'function',
parseDeparture: 'function',
@ -36,7 +36,11 @@ const types = {
const validateProfile = (profile) => {
for (let key of Object.keys(types)) {
const type = types[key]
if (type !== typeof profile[key]) {
if (type === 'array') {
if (!Array.isArray(profile[key])) {
throw new Error(`profile.${key} must be an array.`)
}
} else if (type !== typeof profile[key]) {
throw new Error(`profile.${key} must be a ${type}.`)
}
if (type === 'object' && profile[key] === null) {

View file

@ -69,6 +69,7 @@ const insaProfile = {
endpoint: 'http://reiseauskunft.insa.de/bin/mgate.exe',
transformReqBody,
products: products.allProducts,
parseProducts: createParseBitmask(products.allProducts, defaultProducts),
formatProducts,