Skip to content
Snippets Groups Projects
Commit d2d092e2 authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Add lodash in parseParams.js

parent b5015fe0
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!29Feature param query builder
Pipeline #
......@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment