Skip to content

Commit

Permalink
Removed unnecessary session
Browse files Browse the repository at this point in the history
  • Loading branch information
Nataniel López committed May 26, 2020
1 parent bf44a4d commit b9ea0a2
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `databaseSettings` parameter for `postSaveHook()` method
- `newClientsDatabaseKey` setting for new clients database config

### Removed
- `session` in client create API and Listener

### Changed
- `Client` Model now set the new clients databaseKey from config

Expand Down
7 changes: 3 additions & 4 deletions lib/api-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ class ClientCreateAPI extends API {

get clientModel() {

if(!this._clientModel) {
const instanceGetter = this.session.getSessionInstance(InstanceGetter);
this._clientModel = instanceGetter.getModelInstance('client');
}
if(!this._clientModel)
this._clientModel = InstanceGetter.getModelInstance('client');


return this._clientModel;
}
Expand Down
14 changes: 7 additions & 7 deletions lib/helper/instance-getter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class InstanceGetter {
*/
static getModelClass(entity) {

const modelPath = this.prototype.getModelRelativePath(entity);
const modelPath = this.getModelRelativePath(entity);

try {
return this.prototype.getClass(modelPath);
return this.getClass(modelPath);
} catch(e) {
throw new Error(`Invalid Model ${entity}. Must be in ${modelPath}.`);
}
Expand All @@ -25,7 +25,7 @@ class InstanceGetter {
* Returns an instance model from the service.
* @param {string} entity
*/
getModelInstance(entity) {
static getModelInstance(entity) {

const modelPath = this.getModelRelativePath(entity);

Expand All @@ -36,20 +36,20 @@ class InstanceGetter {
}
}

getModelRelativePath(entity) {
static getModelRelativePath(entity) {
return path.join(process.cwd(), process.env.MS_PATH || '', 'models', entity);
}

getClass(classPath) {
static getClass(classPath) {

// eslint-disable-next-line global-require, import/no-dynamic-require
return require(classPath);
}

getInstance(classPath) {
static getInstance(classPath) {

const TheClass = this.getClass(classPath);
return this.session.getSessionInstance(TheClass);
return new TheClass();
}
}

Expand Down
7 changes: 3 additions & 4 deletions lib/listener-created.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ class ClientCreatedListener extends EventListener {

get clientModel() {

if(!this._clientModel) {
const instanceGetter = this.session.getSessionInstance(InstanceGetter);
this._clientModel = instanceGetter.getModelInstance('client');
}
if(!this._clientModel)
this._clientModel = InstanceGetter.getModelInstance('client');


return this._clientModel;
}
Expand Down
6 changes: 0 additions & 6 deletions tests/api-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ describe('APIs', () => {

{
description: 'Should save all the received new clients to clients DB',
session: true,
request: {
data: {
clients: [
Expand Down Expand Up @@ -99,7 +98,6 @@ describe('APIs', () => {
},
{
description: 'Should return 500 when the client model multiSave fails',
session: true,
request: {
data: {
clients: ['some-client']
Expand Down Expand Up @@ -132,7 +130,6 @@ describe('APIs', () => {
},
{
description: 'Should return 500 when the index creator fails',
session: true,
request: {
data: {
clients: ['some-client']
Expand Down Expand Up @@ -166,7 +163,6 @@ describe('APIs', () => {
},
{
description: 'Should return 400 when the received request data is invalid',
session: true,
request: {
data: ['something']
},
Expand All @@ -176,7 +172,6 @@ describe('APIs', () => {
},
{
description: 'Should return 400 when the received clients are invalid',
session: true,
request: {
data: {
clients: { some: 'object' }
Expand All @@ -188,7 +183,6 @@ describe('APIs', () => {
},
{
description: 'Should return 400 when the client model is not in the corresponding path',
session: true,
request: {
data: {
clients: [
Expand Down
3 changes: 0 additions & 3 deletions tests/listener-created.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ describe('Client Created Listener', async () => {
{
description: 'Should return 500 when client model fails to save the new client',
event: validEvent,
session: true,
before: sandbox => {

mockRequire(fakeClientPath, ClientModel);
Expand All @@ -91,7 +90,6 @@ describe('Client Created Listener', async () => {
{
description: 'Should return 500 when the index creator fails',
event: validEvent,
session: true,
before: sandbox => {

mockRequire(fakeClientPath, ClientModel);
Expand All @@ -116,7 +114,6 @@ describe('Client Created Listener', async () => {
{
description: 'Should return 200 when client model saves the new client sucessfully',
event: validEvent,
session: true,
before: sandbox => {

mockRequire(fakeClientPath, ClientModel);
Expand Down

0 comments on commit b9ea0a2

Please sign in to comment.