Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
simcaq-node
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
simcaq
simcaq-node
Commits
07215e9e
Commit
07215e9e
authored
8 years ago
by
Vytor Calixto
Browse files
Options
Downloads
Patches
Plain Diff
Change queryParam to queryField in parseParams
parent
d2d092e2
No related branches found
No related tags found
2 merge requests
!116
Release v1.0.0
,
!29
Feature param query builder
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/libs/middlewares/parseParams.js
+12
-11
12 additions, 11 deletions
src/libs/middlewares/parseParams.js
with
12 additions
and
11 deletions
src/libs/middlewares/parseParams.js
+
12
−
11
View file @
07215e9e
...
...
@@ -18,17 +18,18 @@ const log = require(`${libs}/log`)(module);
const
_
=
require
(
'
lodash
'
)
function
parseParams
(
query
Param
,
arr
)
{
function
parseParams
(
query
Field
,
arr
)
{
return
(
req
,
res
,
next
)
=>
{
req
[
query
Param
]
=
{};
if
(
req
.
query
[
query
Param
])
{
const
params
=
req
.
query
[
query
Param
].
split
(
'
,
'
);
req
[
query
Field
]
=
{};
if
(
req
.
query
[
query
Field
])
{
const
params
=
req
.
query
[
query
Field
].
split
(
'
,
'
);
// Temporary object to hold the params and it's values
const
obj
=
{};
for
(
const
param
of
params
)
{
// Get the key and the value - state:41 is key 'state' whith value 41
// Get the key and the value - state:41 is key 'state' whith value 41.
// kv is then an array [key, value] or [key] if there is no value
const
kv
=
param
.
split
(
'
:
'
);
// Check if there is a value. If there isn't, assign
null
// Check if there is a value. If there isn't, assign
true
obj
[
kv
[
0
]]
=
(
typeof
kv
[
1
]
===
'
undefined
'
)
?
true
:
kv
[
1
];
}
...
...
@@ -42,14 +43,14 @@ function parseParams(queryParam, arr) {
// and assign it to the custom attribute in the req obj.
// For example: instersection => ["state"] so
// obj[intersection[i]] (with i=0) is obj["state"], that is 41
// and req[query
Param
]["state"] = 41
// and req[query
Field
]["state"] = 41
for
(
let
i
=
0
;
i
<
intersection
.
length
;
++
i
)
{
req
[
query
Param
][
intersection
[
i
]]
=
obj
[
intersection
[
i
]];
req
[
query
Field
][
intersection
[
i
]]
=
obj
[
intersection
[
i
]];
}
req
[
query
Param
].
size
=
intersection
.
length
;
req
[
query
Field
].
size
=
intersection
.
length
;
}
else
{
req
[
query
Param
]
=
obj
;
req
[
query
Param
].
size
=
Object
.
keys
(
obj
).
length
;
req
[
query
Field
]
=
obj
;
req
[
query
Field
].
size
=
Object
.
keys
(
obj
).
length
;
}
}
next
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment