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
a4bda2dc
Commit
a4bda2dc
authored
6 years ago
by
Vytor Calixto
Browse files
Options
Downloads
Plain Diff
Merge branch 'issue/442' into development
parents
0014d69a
3f1db752
No related branches found
No related tags found
No related merge requests found
Pipeline
#16195
failed
6 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.md
+3
-2
3 additions, 2 deletions
CHANGELOG.md
src/libs/middlewares/response.js
+41
-3
41 additions, 3 deletions
src/libs/middlewares/response.js
with
44 additions
and
5 deletions
CHANGELOG.md
+
3
−
2
View file @
a4bda2dc
...
@@ -4,9 +4,10 @@ All notable changes to this project will be documented in this file.
...
@@ -4,9 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on
[
Keep a Changelog
](
http://keepachangelog.com/
)
The format is based on
[
Keep a Changelog
](
http://keepachangelog.com/
)
and this project adheres to
[
Semantic Versioning
](
http://semver.org/
)
.
and this project adheres to
[
Semantic Versioning
](
http://semver.org/
)
.
## U
nreleased
## U
NRELEASED
##
Add
ed
##
# Chang
ed
-
Add school building filter/dimension to school count route
-
Add school building filter/dimension to school count route
-
Fixed CSV output when result objects have nested arrays and/or objects
## 1.3.2 - 2018-06-20
## 1.3.2 - 2018-06-20
### Changed
### Changed
...
...
This diff is collapsed.
Click to expand it.
src/libs/middlewares/response.js
+
41
−
3
View file @
a4bda2dc
...
@@ -3,13 +3,51 @@ const log = require(`${libs}/log`)(module);
...
@@ -3,13 +3,51 @@ const log = require(`${libs}/log`)(module);
const
xml
=
require
(
'
js2xmlparser
'
);
const
xml
=
require
(
'
js2xmlparser
'
);
const
csv
=
require
(
'
csv-express
'
);
const
csv
=
require
(
'
csv-express
'
);
// Custom generic middleware used respond requests.
// Função para transformar um resultado que contém objetos com arrays aninhados em vários objetos
// The function reads the req.query.format param and respond in json, xml or csv
// sem arrays aninhandos
function
flatObj
(
obj
)
{
let
flatList
=
[];
let
tempObj
=
{};
Object
.
keys
(
obj
).
forEach
((
key
)
=>
{
if
(
obj
[
key
]
instanceof
Array
)
{
obj
[
key
].
forEach
((
i
)
=>
{
let
flatten
=
flatObj
(
i
);
if
(
flatten
instanceof
Array
)
{
flatten
.
forEach
((
j
)
=>
{
flatList
.
push
(
Object
.
assign
({},
tempObj
,
j
));
});
}
else
{
flatList
.
push
(
Object
.
assign
({},
tempObj
,
flatten
));
}
});
}
else
if
(
obj
[
key
]
instanceof
Object
)
{
tempObj
=
Object
.
assign
({},
tempObj
,
obj
[
key
]);
}
else
{
tempObj
[
key
]
=
obj
[
key
];
}
});
if
(
flatList
.
length
>
0
)
return
flatList
;
return
tempObj
;
}
// Custom generic middleware used to answer requests.
// The function reads the req.query.format param and answers in json, xml or csv
function
response
(
value
)
{
function
response
(
value
)
{
return
(
req
,
res
,
next
)
=>
{
return
(
req
,
res
,
next
)
=>
{
if
(
req
.
query
.
format
===
'
csv
'
)
{
if
(
req
.
query
.
format
===
'
csv
'
)
{
let
result
=
[];
req
.
result
.
forEach
((
i
)
=>
{
let
flatten
=
flatObj
(
i
);
if
(
flatten
instanceof
Array
)
{
result
=
[...
result
,
...
flatten
];
}
else
{
result
.
push
(
flatten
);
}
});
res
.
attachment
(
`
${
value
}
.csv`
);
res
.
attachment
(
`
${
value
}
.csv`
);
res
.
csv
(
req
.
result
,
true
);
res
.
csv
(
result
,
true
);
}
else
if
(
req
.
query
.
format
===
'
xml
'
)
{
}
else
if
(
req
.
query
.
format
===
'
xml
'
)
{
res
.
send
(
xml
.
parse
(
'
result
'
,
{
[
value
]:
req
.
result
}));
res
.
send
(
xml
.
parse
(
'
result
'
,
{
[
value
]:
req
.
result
}));
}
else
{
}
else
{
...
...
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