db-vendo-client/parse/operator.js

32 lines
575 B
JavaScript
Raw Normal View History

import slugg from 'slugg';
2017-11-11 22:35:41 +01:00
2024-12-07 16:16:31 +00:00
const parseOperator = (ctx, zugattrib) => {
if (zugattrib?.operatorName) {
return {
type: 'operator',
id: zugattrib.operatorCode,
name: zugattrib.operatorName,
};
}
if (!zugattrib || !Array.isArray(zugattrib)) {
return null;
}
2025-01-02 14:00:45 +00:00
const bef = zugattrib.find(z => z.key == 'BEF' || z.key == 'OP');
2024-12-07 16:16:31 +00:00
if (!bef) {
return null;
}
2025-01-02 14:00:45 +00:00
const name = bef.value || bef.text;
if (!name) {
return null;
}
2017-11-11 22:35:41 +01:00
return {
type: 'operator',
2025-01-02 14:00:45 +00:00
id: slugg(name.trim()), // todo: find a more reliable way
name,
};
};
2017-11-11 22:35:41 +01:00
2022-05-07 16:17:37 +02:00
export {
parseOperator,
};