db-vendo-client/parse/warning.js

90 lines
2.4 KiB
JavaScript
Raw Normal View History

2018-06-07 18:46:24 +02:00
'use strict'
2019-03-27 18:31:56 +01:00
const brToNewline = require('@derhuerst/br2nl')
2019-02-25 15:04:25 +01:00
const omit = require('lodash/omit')
2018-06-07 18:46:24 +02:00
const parseDateTime = require('./date-time')
const typesByIcon = Object.assign(Object.create(null), {
HimWarn: 'status'
})
const parseMsgEdge = (profile) => (e) => {
const res = omit(e, [
'icoX',
'fLocX', 'fromLocation',
'tLocX', 'toLocation'
])
2019-08-23 16:02:34 +02:00
res.icon = e.icon || null
// todo: rename `Loc` -> `Location` [breaking]
res.fromLoc = e.fromLocation || null
res.toLoc = e.toLocation || null
2019-02-25 15:04:25 +01:00
return res
}
const parseMsgEvent = (profile) => (e) => {
2019-02-25 15:04:25 +01:00
return {
// todo: rename `Loc` -> `Location` [breaking]
fromLoc: e.fromLocation || null,
toLoc: e.toLocation || null,
2019-02-25 15:04:25 +01:00
start: parseDateTime(profile, e.fDate, e.fTime, null),
end: parseDateTime(profile, e.tDate, e.tTime, null),
sections: e.sectionNums || [] // todo: parse
}
}
const parseWarning = (profile, w, data) => {
2019-08-23 15:36:57 +02:00
// todo: act, pub, lead, tckr, prod, comp,
2019-02-25 15:04:25 +01:00
// todo: cat (1, 2), pubChL, rRefL, impactL
2018-06-07 18:46:24 +02:00
// pubChL:
// [ { name: 'timetable',
// fDate: '20180606',
// fTime: '073000',
// tDate: '20180713',
// tTime: '030000' },
// { name: 'export',
// fDate: '20180606',
// fTime: '073000',
// tDate: '20180713',
// tTime: '030000' } ]
2019-02-25 15:04:25 +01:00
// { name: '1',
// fDate: '20190219',
// fTime: '000000',
// tDate: '20190225',
// tTime: '120000' }
2018-06-07 18:46:24 +02:00
2019-08-23 16:02:34 +02:00
const icon = w.icon || null
2018-10-27 14:50:45 +02:00
const type = icon && icon.type && typesByIcon[icon.type] || 'warning'
const res = {
2019-03-27 18:58:34 +01:00
id: w.hid || null,
type,
2019-02-25 15:04:25 +01:00
summary: w.head ? brToNewline(w.head) : null, // todo: decode HTML entities?
text: w.text ? brToNewline(w.text) : null, // todo: decode HTML entities?
icon,
2018-06-07 18:46:24 +02:00
priority: w.prio,
category: w.cat || null // todo: parse to sth meaningful
2018-06-07 18:46:24 +02:00
}
2019-02-25 15:04:25 +01:00
if ('prod' in w) res.products = profile.parseProducts(w.prod)
if (w.edgeRefL && data.himMsgEdgeL) {
res.edges = w.edgeRefL
.map(i => data.himMsgEdgeL[i])
.filter(e => !!e)
.map(parseMsgEdge(profile))
2019-02-25 15:04:25 +01:00
}
if (w.eventRefL && data.himMsgEventL) {
res.events = w.eventRefL
.map(i => data.himMsgEventL[i])
.filter(e => !!e)
.map(parseMsgEvent(profile))
2019-02-25 15:04:25 +01:00
}
if (w.sDate && w.sTime) res.validFrom = parseDateTime(profile, w.sDate, w.sTime, null)
if (w.eDate && w.eTime) res.validUntil = parseDateTime(profile, w.eDate, w.eTime, null)
if (w.lModDate && w.lModTime) res.modified = parseDateTime(profile, w.lModDate, w.lModTime, null)
return res
2018-06-07 18:46:24 +02:00
}
module.exports = parseWarning