diff --git a/package.json b/package.json index cfc6ffcb..52b990c2 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,6 @@ "helmet": "^3.21.2", "http-status": "^1.4.0", "jsonwebtoken": "^8.5.1", - "lodash": "^4.17.15", "moment": "^2.24.0", "mongoose": "^5.7.7", "morgan": "^1.9.1", diff --git a/src/controllers/user.controller.js b/src/controllers/user.controller.js index d9c9d81c..66b83fa7 100644 --- a/src/controllers/user.controller.js +++ b/src/controllers/user.controller.js @@ -1,5 +1,5 @@ const httpStatus = require('http-status'); -const { pick } = require('lodash'); +const pick = require('../utils/pick'); const ApiError = require('../utils/ApiError'); const catchAsync = require('../utils/catchAsync'); const { userService } = require('../services'); diff --git a/src/middlewares/validate.js b/src/middlewares/validate.js index af2a6caa..2f37c982 100644 --- a/src/middlewares/validate.js +++ b/src/middlewares/validate.js @@ -1,6 +1,6 @@ const Joi = require('@hapi/joi'); const httpStatus = require('http-status'); -const { pick } = require('lodash'); +const pick = require('../utils/pick'); const ApiError = require('../utils/ApiError'); const validate = (schema) => (req, res, next) => { diff --git a/src/utils/pick.js b/src/utils/pick.js new file mode 100644 index 00000000..e4b13c20 --- /dev/null +++ b/src/utils/pick.js @@ -0,0 +1,17 @@ +/** + * Create an object composed of the picked object properties + * @param {Object} object + * @param {string[]} keys + * @returns {Object} + */ +const pick = (object, keys) => { + return keys.reduce((obj, key) => { + if (object && Object.prototype.hasOwnProperty.call(object, key)) { + // eslint-disable-next-line no-param-reassign + obj[key] = object[key]; + } + return obj; + }, {}); +}; + +module.exports = pick;