UNPKG

@trusthab/composable-resources

Version:

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

47 lines (38 loc) 965 B
const _ = require('lodash'); const composer = require('../../mixin_loader'); module.exports = (App) => { class DeviceUpdateReceivedResource { static mixins() { return ['Kpi']; } getMetricId() { return 'device_update_received'; } getMetricType() { return 'counter'; } getValue() { return this.get('obj').command_source === 'hardware' ? 1 : 0; } customDimensions() { return true; } getDimensions() { const dimensions = _.pick(this.get('obj'), [ 'id', 'device_type', 'location_id', 'parent_location_id', 'root_location_id' ]); return { device_id: dimensions.id, type: dimensions.device_type, unit_id: dimensions.location_id, building_id: dimensions.parent_location_id, property_id: dimensions.root_location_id }; } } return composer(DeviceUpdateReceivedResource, App); };