@trusthab/composable-resources
Version:
migrating https://github.com/knetikmedia/hab-api/tree/integration/app/resources/composable
121 lines (108 loc) • 2.61 kB
JavaScript
const composer = require('../mixin_loader');
const moment = require('moment');
module.exports = (App) => {
const { underscore } = require('inflected');
class ObjectCommonResource {
static fields() {
return {
_id: {
schema_ignore: true,
weight: -1001,
type: 'text',
path: 'id'
},
id: {
weight: -1000,
type: 'text',
or: ['null']
},
location_id: {
weight: 60,
or: ['null'],
type: 'text',
path: 'data.location_id'
},
location_name: {
weight: 61,
type: 'text',
or: ['null'],
path: 'data.location_name'
},
location_type: {
weight: 62,
type: 'text',
or: ['null'],
path: 'data.location_type'
},
parent_location_id: {
weight: 63,
type: 'text',
or: ['null'],
path: 'data.parent_location_id'
},
parent_location_name: {
weight: 64,
type: 'text',
or: ['null'],
path: 'data.parent_location_name'
},
parent_location_type: {
weight: 65,
type: 'text',
or: ['null'],
path: 'data.parent_location_type'
},
root_location_id: {
weight: 66,
type: 'text',
or: ['null'],
path: 'data.root_location_id'
},
root_location_name: {
weight: 67,
type: 'text',
or: ['null'],
path: 'data.root_location_name'
},
root_location_type: {
weight: 68,
type: 'text',
or: ['null'],
path: 'data.root_location_type'
},
created_at: {
weight: 1000,
type: 'integer',
or: ['null'],
path: 'created_date'
},
current_server_time: {
weight: 1001.5,
type: 'integer',
persist: false,
get_method: 'getCurrentServerTime'
},
updated_at: {
weight: 1001,
type: 'integer',
or: ['null'],
path: 'updated_date'
},
deleted_at: {
schema_ignore: true,
weight: 1002,
type: 'integer',
or: ['null'],
path: 'data.deleted_at'
}
};
}
static simpleProperties() {
return true;
}
getCurrentServerTime() {
return moment().unix();
}
}
return composer(ObjectCommonResource, App);
};