Skip to content

Commit

Permalink
Partial implementation of API Get
Browse files Browse the repository at this point in the history
  • Loading branch information
jormaechea committed May 20, 2020
1 parent 6257500 commit 2588240
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
32 changes: 32 additions & 0 deletions lib/get-setting-api.js
@@ -0,0 +1,32 @@
'use strict';

const { API } = require('@janiscommerce/api');

const DefinitionFetcher = require('./definition-fetcher');
const ClientSettingsModel = require('./client-settings-model');

module.exports = class GetSettingApi extends API {

async validate() {
this.definition = await DefinitionFetcher.load(this.settingsPath);

const [entity] = this.pathParameters;

if(!this.definition[entity])
throw new Error(`Entity ${entity} has no settings defined`);
}

async process() {

const [entity] = this.pathParameters;

const clientSettingsModel = this.session.getSessionInstance(ClientSettingsModel);
const settings = await clientSettingsModel.getBy('entity', entity);

this.setBody(settings.reduce((acum, { name, value }) => {
acum[name] = value;
return acum;
}, {}));
}

};
4 changes: 3 additions & 1 deletion lib/index.js
Expand Up @@ -4,10 +4,12 @@ const ClientSettings = require('./client-settings');
const ClientIndexes = require('./client-indexes');
const ClientSettingsError = require('./client-settings-error');
const ServerlessHelperHooks = require('./serverless-helper-hooks');
const GetSettingApi = require('./get-setting-api');

module.exports = {
ClientSettings,
ClientSettingsError,
ClientIndexes,
ServerlessHelperHooks
ServerlessHelperHooks,
GetSettingApi
};
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -34,6 +34,7 @@
"test": "tests"
},
"dependencies": {
"@janiscommerce/api": "^4.2.4",
"@janiscommerce/model": "^3.7.0"
}
}

0 comments on commit 2588240

Please sign in to comment.