Skip to content

Commit

Permalink
Minor code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Nataniel López committed Nov 20, 2019
1 parent b7b3210 commit 198b698
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 29 deletions.
36 changes: 8 additions & 28 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,8 @@ class Model {

this.useReadDB = false;

if(this.session && this.session.userId && isObject(item)) {

item = {
...item,
userCreated: this.session.userId
};
}
if(this.session && this.session.userId && isObject(item))
item.userCreated = this.session.userId;

const db = await this.getDb();
const result = await db.insert(this, item);
Expand All @@ -167,20 +162,10 @@ class Model {

if(this.session && this.session.userId && isObject(item)) {

if(typeof item.id !== 'undefined' || typeof item._id !== 'undefined') { // eslint-disable-line no-underscore-dangle

item = {
...item,
userModified: this.session.userId
};

} else {

item = {
...item,
userCreated: this.session.userId
};
}
if(typeof item.id !== 'undefined' || typeof item._id !== 'undefined') // eslint-disable-line no-underscore-dangle
item.userModified = this.session.userId;
else
item.userCreated = this.session.userId;
}

const db = await this.getDb();
Expand All @@ -195,13 +180,8 @@ class Model {

this.useReadDB = false;

if(this.session && this.session.userId && isObject(values)) {

values = {
...values,
userModified: this.session.userId
};
}
if(this.session && this.session.userId && isObject(values))
values.userModified = this.session.userId;

const db = await this.getDb();
const result = await db.update(this, values, filter);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

0 comments on commit 198b698

Please sign in to comment.