From 7d933c0f923d5c903cc123eeac7f457c1b3557c1 Mon Sep 17 00:00:00 2001 From: kl3eo Date: Thu, 20 Feb 2020 15:09:00 +0300 Subject: [PATCH] check if obj is not null --- server/services/admin/index.js | 4 ++-- server/utils/index.js | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/server/services/admin/index.js b/server/services/admin/index.js index b3e6829..c122d43 100644 --- a/server/services/admin/index.js +++ b/server/services/admin/index.js @@ -5,7 +5,7 @@ module.exports = { }, onServerAdminFail: { success: false, - message: 'This are is for admin users only' + message: 'This is for admin users only' }, employeeAddedSuccessfully: { success: true, @@ -27,4 +27,4 @@ module.exports = { success: false, message: 'Please enter username and old or new password.' } -} \ No newline at end of file +} diff --git a/server/utils/index.js b/server/utils/index.js index ad6bda7..762abc0 100644 --- a/server/utils/index.js +++ b/server/utils/index.js @@ -3,10 +3,11 @@ const Activities = require('../models/Activities'); const Employees = require('../models/Employees'); function checkUserControl(id) { + return new Promise((resolve, reject) => { User.findOne({ _id: id }, (error, doc) => { if (error) reject(error); - if (doc.role === 'Admin' || doc.role === 'admin') resolve(true); + if (doc && (doc.role === 'Admin' || doc.role === 'admin')) resolve(true); reject({ success: false, message: 'This is a restricted area and can only be access by Admins.' @@ -35,4 +36,4 @@ module.exports = { checkUserControl: checkUserControl, setActivity: setActivity, getUser: getUser -}; \ No newline at end of file +};