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
Harbor Registry
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
18f0b741
There was a problem fetching the pipeline summary.
Commit
18f0b741
authored
7 years ago
by
Vytor Calixto
Browse files
Options
Downloads
Plain Diff
Merge branch 'idhm_e_route' into development
!59
parents
b0cea9e9
50078834
No related branches found
No related tags found
1 merge request
!116
Release v1.0.0
Pipeline
#
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/libs/routes/api.js
+3
-0
3 additions, 0 deletions
src/libs/routes/api.js
src/libs/routes/idhme.js
+130
-0
130 additions, 0 deletions
src/libs/routes/idhme.js
src/test/idhme.js
+80
-0
80 additions, 0 deletions
src/test/idhme.js
with
213 additions
and
0 deletions
src/libs/routes/api.js
+
3
−
0
View file @
18f0b741
...
@@ -30,6 +30,8 @@ const classroom = require('./classroom');
...
@@ -30,6 +30,8 @@ const classroom = require('./classroom');
const
teacher
=
require
(
'
./teacher
'
);
const
teacher
=
require
(
'
./teacher
'
);
const
idhme
=
require
(
'
./idhme
'
);
api
.
get
(
'
/
'
,
(
req
,
res
)
=>
{
api
.
get
(
'
/
'
,
(
req
,
res
)
=>
{
res
.
json
({
msg
:
'
SimCAQ API is running
'
});
res
.
json
({
msg
:
'
SimCAQ API is running
'
});
});
});
...
@@ -46,5 +48,6 @@ api.use('/school', cache('15 day'), school);
...
@@ -46,5 +48,6 @@ api.use('/school', cache('15 day'), school);
api
.
use
(
'
/spatial
'
,
cache
(
'
1 day
'
),
spatial
);
api
.
use
(
'
/spatial
'
,
cache
(
'
1 day
'
),
spatial
);
api
.
use
(
'
/classroom
'
,
cache
(
'
15 day
'
),
classroom
);
api
.
use
(
'
/classroom
'
,
cache
(
'
15 day
'
),
classroom
);
api
.
use
(
'
/teacher
'
,
cache
(
'
1 day
'
),
teacher
);
api
.
use
(
'
/teacher
'
,
cache
(
'
1 day
'
),
teacher
);
api
.
use
(
'
/idhme
'
,
cache
(
'
15 day
'
),
idhme
);
module
.
exports
=
api
;
module
.
exports
=
api
;
This diff is collapsed.
Click to expand it.
src/libs/routes/idhme.js
0 → 100644
+
130
−
0
View file @
18f0b741
const
express
=
require
(
'
express
'
);
const
idhmeApp
=
express
.
Router
();
const
libs
=
`
${
process
.
cwd
()}
/libs`
;
const
squel
=
require
(
'
squel
'
);
const
query
=
require
(
`
${
libs
}
/middlewares/query`
);
const
response
=
require
(
`
${
libs
}
/middlewares/response`
);
const
id2str
=
require
(
`
${
libs
}
/middlewares/id2str`
);
const
ReqQueryFields
=
require
(
`
${
libs
}
/middlewares/reqQueryFields`
);
let
rqf
=
new
ReqQueryFields
();
idhmeApp
.
get
(
'
/year_range
'
,
(
req
,
res
,
next
)
=>
{
req
.
sql
.
from
(
'
adh_idh
'
)
.
field
(
'
MIN(adh_idh.ano_censo)
'
,
'
start_year
'
)
.
field
(
'
MAX(adh_idh.ano_censo)
'
,
'
end_year
'
);
next
();
},
query
,
(
req
,
res
,
next
)
=>
{
req
.
sql
.
from
(
'
adh_idh_uf
'
)
.
field
(
'
MIN(adh_idh_uf.ano_censo)
'
,
'
start_year
'
)
.
field
(
'
MAX(adh_idh_uf.ano_censo)
'
,
'
end_year
'
);
req
.
old_result
=
req
.
result
;
next
();
},
query
,
(
req
,
res
,
next
)
=>
{
// console.log(req.old_result[0].start_year);
// console.log(req.result[0].start_year);
if
(
req
.
old_result
[
0
].
start_year
<
req
.
result
[
0
].
start_year
)
{
req
.
result
[
0
].
start_year
=
req
.
old_result
[
0
].
start_year
;
}
if
(
req
.
old_result
[
0
].
end_year
>
req
.
result
[
0
].
end_year
)
{
req
.
result
[
0
].
end_year
=
req
.
old_result
[
0
].
old_result
;
}
next
();
},
query
,
response
(
'
range
'
));
rqf
.
addField
({
name
:
'
filter
'
,
field
:
false
,
where
:
true
}).
addValue
({
name
:
'
city
'
,
table
:
'
municipio
'
,
tableField
:
'
nome
'
,
resultField
:
'
city_name
'
,
where
:
{
relation
:
'
=
'
,
type
:
'
integer
'
,
field
:
'
municipio_id
'
,
table
:
'
adh_idh
'
},
join
:
{
primary
:
'
id
'
,
foreign
:
'
municipio_id
'
,
foreignTable
:
'
adh_idh
'
}
}).
addValue
({
name
:
'
min_year
'
,
table
:
'
@
'
,
tableField
:
'
ano_censo
'
,
resultField
:
'
year
'
,
where
:
{
relation
:
'
>=
'
,
type
:
'
integer
'
,
table
:
'
@
'
,
field
:
'
ano_censo
'
}
}).
addValue
({
name
:
'
max_year
'
,
table
:
'
@
'
,
tableField
:
'
ano_censo
'
,
resultField
:
'
year
'
,
where
:
{
relation
:
'
<=
'
,
type
:
'
integer
'
,
table
:
'
@
'
,
field
:
'
ano_censo
'
}
}).
addValue
({
name
:
'
state
'
,
table
:
'
estado
'
,
tableField
:
'
nome
'
,
resultField
:
'
state_name
'
,
where
:
{
relation
:
'
=
'
,
type
:
'
integer
'
,
field
:
'
estado_id
'
,
table
:
'
adh_idh_uf
'
},
join
:
{
primary
:
'
id
'
,
foreign
:
'
estado_id
'
,
foreignTable
:
'
adh_idh_uf
'
}
});
idhmeApp
.
get
(
'
/
'
,
rqf
.
parse
(),
(
req
,
res
,
next
)
=>
{
if
(
typeof
req
.
filter
===
'
undefined
'
||
Object
.
keys
(
req
.
filter
).
length
===
0
)
{
res
.
status
(
400
);
next
({
status
:
400
,
message
:
'
Wrong/No filter specified
'
});
}
if
(
"
state
"
in
req
.
filter
)
{
// console.log("sim");
req
.
sql
.
from
(
'
adh_idh_uf
'
)
.
field
(
'
adh_idh_uf.idhm_e
'
,
'
total
'
)
.
field
(
'
adh_idh_uf.ano_censo
'
,
'
year
'
)
.
field
(
'
adh_idh_uf.estado_id
'
,
'
state_id
'
);
}
else
if
(
"
city
"
in
req
.
filter
)
{
req
.
sql
.
from
(
'
adh_idh
'
)
.
field
(
'
adh_idh.idhm_e
'
,
'
IDHME
'
)
.
field
(
'
adh_idh.ano_censo
'
,
'
year
'
)
.
field
(
'
adh_idh.municipio_id
'
,
'
city_id
'
);
}
else
{
next
({
status
:
400
,
message
:
'
Wrong/No filter specified
'
});
}
next
();
},
rqf
.
build
(),
query
,
response
(
'
idhme
'
));
module
.
exports
=
idhmeApp
;
This diff is collapsed.
Click to expand it.
src/test/idhme.js
0 → 100644
+
80
−
0
View file @
18f0b741
process
.
env
.
NODE_ENV
=
'
test
'
;
const
chai
=
require
(
'
chai
'
);
const
dirtyChai
=
require
(
'
dirty-chai
'
);
chai
.
use
(
dirtyChai
);
const
chaiXml
=
require
(
'
chai-xml
'
);
chai
.
use
(
chaiXml
);
const
chaiHttp
=
require
(
'
chai-http
'
);
const
assert
=
chai
.
assert
;
const
expect
=
chai
.
expect
;
const
should
=
chai
.
should
();
// actually call the function
const
libs
=
`
${
process
.
cwd
()}
/libs`
;
const
server
=
require
(
`
${
libs
}
/app`
);
chai
.
use
(
chaiHttp
);
describe
(
'
request idhme
'
,
()
=>
{
it
(
'
should list the year range
'
,
(
done
)
=>
{
chai
.
request
(
server
)
.
get
(
'
/api/v1/idhme/year_range
'
)
.
end
((
err
,
res
)
=>
{
res
.
should
.
have
.
status
(
200
);
res
.
should
.
be
.
json
;
res
.
body
.
should
.
have
.
property
(
'
result
'
);
res
.
body
.
result
.
should
.
be
.
a
(
'
array
'
);
res
.
body
.
result
[
0
].
should
.
have
.
property
(
'
start_year
'
);
res
.
body
.
result
[
0
].
should
.
have
.
property
(
'
end_year
'
);
done
();
});
});
it
(
'
should list idhme with valid filters
'
,
(
done
)
=>
{
chai
.
request
(
server
)
.
get
(
'
/api/v1/idhme?filter=min_year:2000,state:41
'
)
.
end
((
err
,
res
)
=>
{
res
.
should
.
have
.
status
(
200
);
res
.
should
.
be
.
json
;
res
.
body
.
should
.
have
.
property
(
'
result
'
);
res
.
body
.
result
.
should
.
be
.
a
(
'
array
'
);
res
.
body
.
result
[
0
].
should
.
have
.
property
(
'
total
'
);
res
.
body
.
result
[
0
].
should
.
have
.
property
(
'
year
'
);
res
.
body
.
result
[
0
].
should
.
have
.
property
(
'
state_id
'
);
done
();
});
});
it
(
'
should list idhme with invalid filters
'
,
(
done
)
=>
{
chai
.
request
(
server
)
.
get
(
'
/api/v1/idhme?filter=foo:2010,bar:41
'
)
.
end
((
err
,
res
)
=>
{
res
.
should
.
have
.
status
(
400
);
res
.
should
.
be
.
json
;
res
.
body
.
should
.
have
.
property
(
'
error
'
);
res
.
body
.
error
.
should
.
be
.
equal
(
'
Wrong/No filter specified
'
);
done
();
});
});
it
(
'
should return 400 with no filters
'
,
(
done
)
=>
{
chai
.
request
(
server
)
.
get
(
'
/api/v1/idhme
'
)
.
end
((
err
,
res
)
=>
{
res
.
should
.
have
.
status
(
400
);
res
.
should
.
be
.
json
;
res
.
body
.
should
.
have
.
property
(
'
error
'
);
res
.
body
.
error
.
should
.
be
.
equal
(
'
Wrong/No filter specified
'
);
done
();
})
});
});
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