@trusthab/composable-resources
Version:
migrating https://github.com/knetikmedia/hab-api/tree/integration/app/resources/composable
107 lines (98 loc) • 2.77 kB
JavaScript
const composer = require('../mixin_loader');
module.exports = (App) => {
const { underscore } = require('inflected');
// Example used to demo the Knetik Cloud Persistence Mixin.
class DeviceGatewayResource {
static mixins() {
return ['DeviceBase'];
}
static fields() {
return {
cpu_load: {
type: 'text',
or: ['null'],
path: 'additional_properties.cpu_load.value'
},
cpu_temp: {
type: 'text',
or: ['null'],
path: 'additional_properties.cpu_temp.value'
},
memory_usage: {
type: 'text',
or: ['null'],
path: 'additional_properties.memory_usage.value'
},
users_logged_in: {
type: 'text',
or: ['null'],
path: 'additional_properties.users_logged_in.value'
},
hardware_info: {
type: 'text',
or: ['null'],
path: 'additional_properties.hardware_info.value'
},
interval_heartbeat: {
type: 'integer',
or: ['null'],
path: 'additional_properties.interval_heartbeat.value'
},
interval_commands: {
type: 'integer',
or: ['null'],
path: 'additional_properties.interval_commands.value'
},
reboot: {
type: 'boolean',
or: ['null'],
path: 'additional_properties.reboot.value'
},
update_code: {
type: 'text',
or: ['null'],
path: 'additional_properties.update_code.value'
},
tunnel: {
type: 'boolean',
or: ['null'],
path: 'additional_properties.tunnel.value'
},
tunnel_port: {
type: 'integer',
or: ['null'],
path: 'additional_properties.tunnel_port.value'
},
reboot_devices: {
type: 'text',
or: ['null'],
path: 'additional_properties.reboot_devices.value'
},
refresh_values: {
type: 'text',
or: ['null'],
path: 'additional_properties.refresh_values.value'
}
};
}
static knetikCloudMethods() {
const methods = require('./device_base')(App).knetikCloudMethods();
return {
...methods,
search: {
index: 'devices',
template: 'hab',
paramsBuilder: (params) => {
const { filter } = params;
const default_filters = 'device_type:gateway';
params.filter = filter
? `${filter}|${default_filters}`
: default_filters;
return params;
}
}
};
}
}
return composer(DeviceGatewayResource, App);
};