diff --git a/src/libs/middlewares/parseParams.js b/src/libs/middlewares/parseParams.js index 36361f274b13ebeaeff709bc2b48e4869682a47c..3f841e15920dccc0d2ff0875f622a743ea957bb9 100644 --- a/src/libs/middlewares/parseParams.js +++ b/src/libs/middlewares/parseParams.js @@ -16,14 +16,7 @@ const libs = `${process.cwd()}/libs`; const log = require(`${libs}/log`)(module); - // This function returns the intersection of two arrays -function intersect(a, b) { - let t; - if (b.length > a.length) { - t = b; b = a; a = t; - } - return a.filter((e) => b.indexOf(e) !== -1); -} +const _ = require('lodash') function parseParams(queryParam, arr) { return (req, res, next) => { @@ -43,7 +36,7 @@ function parseParams(queryParam, arr) { if (typeof arr !== 'undefined' && arr.length > 0) { // Intersect the keys of the obj with the array arr. // The intersection array is assigned with the keys - const intersection = intersect(arr, Object.keys(obj)); + const intersection = _.intersection(arr, Object.keys(obj)); // This is a bit tricky... // For each key in the intersection array we get it's value in the obj // and assign it to the custom attribute in the req obj.