mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 23:29:35 +02:00
fix profile and profile validation 🐛
This commit is contained in:
parent
a10e9487bd
commit
551d2b8215
2 changed files with 7 additions and 2 deletions
|
@ -7,7 +7,7 @@ const types = {
|
||||||
transformReqBody: 'function',
|
transformReqBody: 'function',
|
||||||
transformJourneysQuery: 'function',
|
transformJourneysQuery: 'function',
|
||||||
|
|
||||||
products: 'object',
|
products: 'array',
|
||||||
|
|
||||||
parseDateTime: 'function',
|
parseDateTime: 'function',
|
||||||
parseDeparture: 'function',
|
parseDeparture: 'function',
|
||||||
|
@ -36,7 +36,11 @@ const types = {
|
||||||
const validateProfile = (profile) => {
|
const validateProfile = (profile) => {
|
||||||
for (let key of Object.keys(types)) {
|
for (let key of Object.keys(types)) {
|
||||||
const type = types[key]
|
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}.`)
|
throw new Error(`profile.${key} must be a ${type}.`)
|
||||||
}
|
}
|
||||||
if (type === 'object' && profile[key] === null) {
|
if (type === 'object' && profile[key] === null) {
|
||||||
|
|
|
@ -69,6 +69,7 @@ const insaProfile = {
|
||||||
endpoint: 'http://reiseauskunft.insa.de/bin/mgate.exe',
|
endpoint: 'http://reiseauskunft.insa.de/bin/mgate.exe',
|
||||||
transformReqBody,
|
transformReqBody,
|
||||||
|
|
||||||
|
products: products.allProducts,
|
||||||
parseProducts: createParseBitmask(products.allProducts, defaultProducts),
|
parseProducts: createParseBitmask(products.allProducts, defaultProducts),
|
||||||
formatProducts,
|
formatProducts,
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue