@trusthab/composable-resources
Version:
migrating https://github.com/knetikmedia/hab-api/tree/integration/app/resources/composable
34 lines (25 loc) • 682 B
JavaScript
const composer = require('../../mixin_loader');
module.exports = (App) => {
const { underscore } = require('inflected');
const PROPERTY_VALUE = 'offline';
class DevicesOfflineResource {
static mixins() {
return ['Kpi'];
}
getMetricId() {
return `devices_${PROPERTY_VALUE}`;
}
getMetricType() {
return 'gauge';
}
getValue() {
if (this.get('obj').device_type === 'gateway') { return 0; }
const { value, oldValue } = this.get('diff');
if (oldValue !== PROPERTY_VALUE && value === PROPERTY_VALUE) {
return 1;
}
return 0;
}
}
return composer(DevicesOfflineResource, App);
};