Skip to content

Commit

Permalink
Put manual empty checks instead of reply transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
XVincentX committed Nov 13, 2017
1 parent b7a9754 commit 020cf71
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 16 deletions.
5 changes: 2 additions & 3 deletions lib/services/authorization-codes/authorization-code.dao.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

const isEmpty = require('lodash.isempty');
const db = require('../../db');
const config = require('../../config');

Expand All @@ -16,7 +15,7 @@ dao.save = function (code) {
dao.find = function (criteria) {
return db.hgetall(config.systemConfig.db.redis.namespace.concat('-', authCodeNamespace).concat(':', criteria.id))
.then((code) => {
if (!code) {
if (isEmpty(code)) {
return null;
}
code.expiresAt = parseInt(code.expiresAt);
Expand Down
5 changes: 2 additions & 3 deletions lib/services/consumers/application.dao.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

const isEmpty = require('lodash.isEmpty');
const db = require('../../db');
const config = require('../../config');

Expand Down Expand Up @@ -54,7 +53,7 @@ dao.findAll = function (query) {
dao.get = function (id) {
return db.hgetall(config.systemConfig.db.redis.namespace.concat('-', appNamespace).concat(':', id))
.then(function (app) {
if (!app || !Object.keys(app).length) {
if (!app || isEmpty(app)) {
return false;
} else return app;
});
Expand Down
5 changes: 2 additions & 3 deletions lib/services/consumers/user.dao.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

const isEmpty = require('lodash.isEmpty');
const db = require('../../db');
const config = require('../../config');

Expand All @@ -25,7 +24,7 @@ dao.insert = function (user) {
dao.getUserById = function (userId) {
return db.hgetall(config.systemConfig.db.redis.namespace.concat('-', userNamespace).concat(':', userId))
.then(function (user) {
if (!user || !Object.keys(user).length) {
if (!user || isEmpty(user)) {
return false;
}
return user;
Expand Down
9 changes: 4 additions & 5 deletions lib/services/credentials/credential.dao.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';

const scopeNamespace = 'scope';
const scopeCredentialsNamespace = 'scope-credentials';
const isEmpty = require('lodash.isempty');
const db = require('../../db');
const config = require('../../config');
const logger = require('../../../lib/logger').gateway;
const scopeNamespace = 'scope';
const scopeCredentialsNamespace = 'scope-credentials';
const scopeDbKey = config.systemConfig.db.redis.namespace.concat('-', scopeNamespace);

const dao = {};
Expand Down Expand Up @@ -126,7 +125,7 @@ dao.insertCredential = function (id, type, credentialObj) {

dao.getCredential = function (id, type) {
return db.hgetall(buildIdKey(type, id)).then(credential => {
if (!credential) return null;
if (isEmpty(credential)) return null;
credential.isActive = credential.isActive === 'true'; // Redis has no bool type, manual conversion
credential.type = type;
return credential;
Expand Down
5 changes: 3 additions & 2 deletions lib/services/tokens/token.dao.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const isEmpty = require('lodash.isempty');
const db = require('../../db');
const config = require('../../config');

Expand Down Expand Up @@ -56,7 +57,7 @@ dao.find = function (tokenObj, options) {
.then((tokenIds) => {
const expiredTokenIds = [];

if (!tokenIds || Object.keys(tokenIds).length === 0) {
if (!tokenIds || isEmpty(tokenIds)) {
return null;
}

Expand Down Expand Up @@ -121,7 +122,7 @@ dao.get = function (tokenId, options) {

return db.hgetall(tokenNamespace.concat(':', tokenId))
.then(token => {
if (!token) {
if (isEmpty(token)) {
return null;
}
if (token.archived) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"ioredis": "^3.2.1",
"ioredis-mock": "^3.1.3",
"js-yaml": "^3.10.0",
"lodash.isempty": "^4.4.0",
"migrate": "^1.0.0-2",
"minimatch": "^3.0.4",
"oauth2orize": "^1.10.0",
Expand Down

0 comments on commit 020cf71

Please sign in to comment.