UNPKG

@trusthab/composable-resources

Version:

migrating https://github.com/knetikmedia/hab-api/tree/integration/app/resources/composable

42 lines (33 loc) 910 B
const composer = require('../../mixin_loader'); module.exports = (App) => { const { underscore } = require('inflected'); class DevicesActiveResource { static mixins() { return ['Kpi']; } getMetricId() { return 'devices_active'; } getMetricType() { return 'gauge'; } getValue() { const { location_type } = this.get('obj'); const { oldValue } = this.get('diff'); switch (this.get('transaction')) { case 'created': return location_type === 'unit' ? 1 : 0; case 'updated': if (oldValue === 'unit' && location_type !== 'unit') { return 0; } if (oldValue !== 'unit' && location_type === 'unit') { return 1; } break; case 'deleted': return 0; default: return 0; } return null; } } return composer(DevicesActiveResource, App); };