@trusthab/composable-resources
Version:
migrating https://github.com/knetikmedia/hab-api/tree/integration/app/resources/composable
53 lines (40 loc) • 1 kB
JavaScript
const _ = require('lodash');
const composer = require('../../mixin_loader');
module.exports = (App) => {
class AlertRunningResource {
static mixins() {
return ['Kpi'];
}
getMetricId() {
return 'alert_running';
}
getMetricType() {
return 'gauge';
}
getValue() {
const { archived } = this.get('obj');
const { value } = this.get('diff');
if (archived) { return 0; }
if (value !== 'resolved') { return 1; }
return 0;
}
customDimensions() {
return true;
}
getDimensions() {
const dimensions = _.pick(this.get('obj'), [
'id',
'location_id',
'parent_location_id',
'root_location_id'
]);
return {
alert_id: dimensions.id,
unit_id: dimensions.location_id,
building_id: dimensions.parent_location_id,
property_id: dimensions.root_location_id
};
}
}
return composer(AlertRunningResource, App);
};