From 8e5eca56296c16a183d243244f9f7600571b5766 Mon Sep 17 00:00:00 2001 From: Dani Herrero Date: Wed, 4 Oct 2017 08:33:51 +0200 Subject: [PATCH] validation client credit - refact --- services/client/common/models/client.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/services/client/common/models/client.js b/services/client/common/models/client.js index 106ccd2ef..19c3969a9 100644 --- a/services/client/common/models/client.js +++ b/services/client/common/models/client.js @@ -121,7 +121,12 @@ module.exports = function(Client) { function maxCb(_, instances) { //console.log('maxCb', instances); - if (instances && (instances.length !== 1 || instances[0].employeeFk == userId || instances[0].amount > 0)) { + if(!instances){ + err(); + return; + } + + if (instances.length !== 1 || instances[0].employeeFk == userId || instances[0].amount > 0) { done(); return; } @@ -141,7 +146,7 @@ module.exports = function(Client) { } function clientCreditCb(_, instance) { - if (instance.length && instance[0].hasManagerRole > 0 ) + if (!instance || (instance.length && instance[0].hasManagerRole > 0 )) err(); done(); }