@trusthab/composable-resources
Version:
migrating https://github.com/knetikmedia/hab-api/tree/integration/app/resources/composable
113 lines (103 loc) • 2.71 kB
JavaScript
const composer = require('../mixin_loader');
const moment = require('moment');
module.exports = (App) => {
const { underscore } = require('inflected');
class CommonResource {
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: 'additional_properties.location_id.value'
},
location_name: {
weight: 61,
type: 'text',
or: ['null'],
path: 'additional_properties.location_name.value'
},
location_type: {
weight: 62,
type: 'text',
or: ['null'],
path: 'additional_properties.location_type.value'
},
parent_location_id: {
weight: 63,
type: 'text',
or: ['null'],
path: 'additional_properties.parent_location_id.value'
},
parent_location_name: {
weight: 64,
type: 'text',
or: ['null'],
path: 'additional_properties.parent_location_name.value'
},
parent_location_type: {
weight: 65,
type: 'text',
or: ['null'],
path: 'additional_properties.parent_location_type.value'
},
root_location_id: {
weight: 66,
type: 'text',
or: ['null'],
path: 'additional_properties.root_location_id.value'
},
root_location_name: {
weight: 67,
type: 'text',
or: ['null'],
path: 'additional_properties.root_location_name.value'
},
root_location_type: {
weight: 68,
type: 'text',
or: ['null'],
path: 'additional_properties.root_location_type.value'
},
created_at: {
weight: 1000,
type: 'integer',
or: ['null']
},
updated_at: {
weight: 1001,
type: 'integer',
or: ['null']
},
current_server_time: {
weight: 1001.5,
type: 'integer',
persist: false,
get_method: 'getCurrentServerTime'
},
deleted_at: {
schema_ignore: true,
weight: 1002,
type: 'integer',
or: ['null'],
path: 'additional_properties.deleted_at.value'
}
};
}
getCurrentServerTime() {
return moment().unix();
}
}
return composer(CommonResource, App);
};