@trusthab/composable-resources
Version:
migrating https://github.com/knetikmedia/hab-api/tree/integration/app/resources/composable
285 lines (272 loc) • 7.36 kB
JavaScript
const composer = require('../mixin_loader');
module.exports = (App) => {
const { underscore } = require('inflected');
class LocationResource {
static mixins() {
return [
// Functionality
'Validatable',
'Templatable',
// ORMish
'Persistable',
'AreasPersistence'
];
}
static fields() {
return {
_id: {
schema_ignore: true,
type: 'text',
path: '_id'
},
id: {
type: 'text',
or: ['null'],
path: 'id'
},
command_source: {
type: 'text',
or: ['null'],
path: 'additional_properties.command_source.value'
},
name: {
type: 'text',
path: 'name',
minLength: 1
},
description: {
type: 'text',
or: ['null'],
path: 'description'
},
address: {
type: 'text',
or: ['null'],
path: 'additional_properties.address.value'
},
coordinates: {
type: 'list',
path: 'additional_properties.coordinates.values'
},
status: {
type: 'text',
or: ['null'],
path: 'additional_properties.activity_status.value'
},
problem_statuses: {
type: 'list',
path: 'additional_properties.problem_statuses.values'
},
parent_location_id: {
type: 'text',
or: ['null'],
path: 'parent'
},
parent_location_name: {
type: 'text',
path: 'additional_properties.parent_location_name.value'
},
parent_location_type: {
type: 'text',
path: 'additional_properties.parent_location_type.value'
},
root_location_id: {
type: 'text',
or: ['null'],
path: 'additional_properties.root_location_id.value'
},
root_location_name: {
type: 'text',
or: ['null'],
path: 'additional_properties.root_location_name.value'
},
root_location_type: {
type: 'text',
or: ['null'],
path: 'additional_properties.root_location_type.value'
},
auto_mode: {
type: 'text',
or: ['null'],
enum: ['auto', 'heat', 'cool', 'off', null],
path: 'additional_properties.auto_mode.value'
},
climate_mode: {
type: 'text',
path: 'additional_properties.climate_mode.value',
$ref: '/ClimateMode'
},
current_temp: {
type: 'integer',
or: ['null'],
path: 'additional_properties.current_temp.value'
},
target_temp: {
type: 'integer',
or: ['null'],
path: 'additional_properties.target_temp.value'
},
delta: {
type: 'integer',
or: ['null'],
path: 'additional_properties.delta.value'
},
cool_min: {
type: 'integer',
path: 'additional_properties.cool_min.value'
},
cool_max: {
type: 'integer',
path: 'additional_properties.cool_max.value'
},
cool_target: {
type: 'integer',
path: 'additional_properties.cool_target.value'
},
heat_min: {
type: 'integer',
path: 'additional_properties.heat_min.value'
},
heat_max: {
type: 'integer',
path: 'additional_properties.heat_max.value'
},
heat_target: {
type: 'integer',
path: 'additional_properties.heat_target.value'
},
auto_min: {
type: 'integer',
path: 'additional_properties.auto_min.value'
},
auto_max: {
type: 'integer',
path: 'additional_properties.auto_max.value'
},
connected: {
type: 'boolean',
or: ['null', 'number'],
path: 'additional_properties.connected.value'
},
fan_speed: {
type: 'text',
$ref: '/FanSpeed',
path: 'additional_properties.fan_speed.value'
},
activity_status: {
type: 'text',
$ref: '/RequiredOnOff',
path: 'additional_properties.status.value'
},
runtime: {
type: 'integer',
or: ['null'],
path: 'additional_properties.runtime.value'
},
locked: {
type: 'boolean',
or: ['null'],
path: 'additional_properties.locked.value'
},
default_profile: {
type: 'boolean',
or: ['null'],
path: 'additional_properties.default_profile.value'
},
profile_type: {
type: 'text',
or: ['null'],
enum: ['default', 'manual', 'custom', null],
path: 'additional_properties.profile_type.value'
},
profile_id: {
type: 'integer',
path: 'additional_properties.global_settings_id.value'
},
selected_profile_id: {
type: 'integer',
or: ['null'],
path: 'additional_properties.profile_id.value'
},
profile_name: {
type: 'text',
path: 'additional_properties.global_settings_name.value'
},
occupied: {
type: 'boolean',
or: ['null'],
path: 'additional_properties.occupied.value'
},
synced: {
type: 'boolean',
or: ['null'],
path: 'additional_properties.synced.value'
},
alert_state: {
type: 'text',
persist: false,
$ref: '/AlertState',
path: 'additional_properties.alert_state.value'
},
type: {
type: 'text',
path: 'additional_properties.type.value'
},
tags: {
type: 'array',
items: { type: 'string' },
path: 'tags'
},
devices_types: {
type: 'array',
items: { type: 'string' },
},
devices_count: {
type: 'integer',
or: ['null']
},
humidity: {
type: 'double',
or: ['null'],
path: 'additional_properties.humidity.value'
},
created_at: {
type: 'integer',
or: ['null'],
path: 'created_at'
},
updated_at: {
type: 'integer',
or: ['null'],
path: 'updated_at'
},
deleted_at: {
type: 'integer',
or: ['null'],
path: 'additional_properties.deleted_at.value'
}
};
}
getScope() {
const { location_type, parent_location_name, location_name } = this;
if (location_type === 'unit') { return parent_location_name; }
return location_name;
}
static areasParams_count() {
return { filter: {} };
}
static areasParams_list() {
return { filter: {} };
}
static areasParams_create() {
return {};
}
static areasParams_update() {
return {};
}
static customFilters() {
return require('./location_filters')(App);
}
}
return composer(LocationResource, App);
};