@trusthab/composable-resources
Version:
migrating https://github.com/knetikmedia/hab-api/tree/integration/app/resources/composable
81 lines (71 loc) • 1.66 kB
JavaScript
const composer = require('../mixin_loader');
module.exports = (App) => {
const { underscore } = require('inflected');
class ConfigResource {
static mixins() {
return [
// Functionality
'Validatable',
'Templatable',
// ORMish
'Persistable',
'KnetikCloudPersistence'
];
}
static fields() {
return {
id: {
type: 'text',
path: 'name',
get_method: 'getName'
},
name: {
type: 'text',
get_method: 'getName'
},
description: {
type: 'text'
},
public_read: {
type: 'boolean'
},
value: {
type: 'text',
or: ['any']
}
};
}
getName() {
return this.get('name').replace(/^_hab_/, "");
}
static knetikCloudMethods() {
return {
list: {
api: 'ConfigsApi',
method: 'getConfigs',
paramsBuilder: (params) => {
params.filterSearch = '_hab';
params.order = params.order || 'name:DESC';
return params;
}
},
find: {
api: 'ConfigsApi',
method: 'getConfig',
paramsBuilder: id => [`_hab_${id}`]
},
update: {
api: 'ConfigsApi',
method: 'updateConfig',
paramsBuilder: (id, params) => {
id = `_hab_${id}`;
params.name = `_hab_${id}`;
params = { config: params };
return [id, params];
}
}
};
}
}
return composer(ConfigResource, App);
};