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
fe90fbc3
Commit
fe90fbc3
authored
6 years ago
by
Victor Picussa
Browse files
Options
Downloads
Patches
Plain Diff
[cub]Created CUB route
parent
ef808fa0
No related branches found
No related tags found
1 merge request
!133
Release v1.4.0
Pipeline
#16251
failed
6 years ago
Stage: test
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/cub.js
+152
-0
152 additions, 0 deletions
src/libs/routes/cub.js
src/test/cub.js
+109
-0
109 additions, 0 deletions
src/test/cub.js
with
264 additions
and
0 deletions
src/libs/routes/api.js
+
3
−
0
View file @
fe90fbc3
...
@@ -66,6 +66,8 @@ const classroomCount = require(`${libs}/routes/classroomCount`);
...
@@ -66,6 +66,8 @@ const classroomCount = require(`${libs}/routes/classroomCount`);
const
dailyChargeAmount
=
require
(
`
${
libs
}
/routes/dailyChargeAmount`
);
const
dailyChargeAmount
=
require
(
`
${
libs
}
/routes/dailyChargeAmount`
);
const
cub
=
require
(
`
${
libs
}
/routes/cub`
);
api
.
get
(
'
/
'
,
(
req
,
res
)
=>
{
api
.
get
(
'
/
'
,
(
req
,
res
)
=>
{
res
.
json
({
msg
:
'
SimCAQ API is running
'
});
res
.
json
({
msg
:
'
SimCAQ API is running
'
});
});
});
...
@@ -101,5 +103,6 @@ api.use('/siope', siope);
...
@@ -101,5 +103,6 @@ api.use('/siope', siope);
api
.
use
(
'
/out_of_school
'
,
outOfSchool
);
api
.
use
(
'
/out_of_school
'
,
outOfSchool
);
api
.
use
(
'
/classroom_count
'
,
classroomCount
);
api
.
use
(
'
/classroom_count
'
,
classroomCount
);
api
.
use
(
'
/daily_charge_amount
'
,
dailyChargeAmount
);
api
.
use
(
'
/daily_charge_amount
'
,
dailyChargeAmount
);
api
.
use
(
'
/cub
'
,
cub
);
module
.
exports
=
api
;
module
.
exports
=
api
;
This diff is collapsed.
Click to expand it.
src/libs/routes/cub.js
0 → 100644
+
152
−
0
View file @
fe90fbc3
const
express
=
require
(
'
express
'
);
const
cubApp
=
express
.
Router
();
const
libs
=
`
${
process
.
cwd
()}
/libs`
;
const
log
=
require
(
`
${
libs
}
/log`
)(
module
);
const
squel
=
require
(
'
squel
'
);
const
query
=
require
(
`
${
libs
}
/middlewares/query`
).
query
;
const
response
=
require
(
`
${
libs
}
/middlewares/response`
);
const
id2str
=
require
(
`
${
libs
}
/middlewares/id2str`
);
const
ReqQueryFields
=
require
(
`
${
libs
}
/middlewares/reqQueryFields`
);
const
request
=
require
(
`request`
);
const
config
=
require
(
`
${
libs
}
/config`
);
const
passport
=
require
(
'
passport
'
);
const
download
=
require
(
`
${
libs
}
/middlewares/downloadDatabase`
);
const
addMissing
=
require
(
`
${
libs
}
/middlewares/addMissing`
);
const
cache
=
require
(
'
apicache
'
).
options
({
debug
:
config
.
debug
,
statusCodes
:
{
include
:
[
200
]}
}).
middleware
;
let
rqf
=
new
ReqQueryFields
();
let
rqfCount
=
new
ReqQueryFields
();
cubApp
.
get
(
'
/year_range
'
,
(
req
,
res
,
next
)
=>
{
req
.
sql
.
from
(
'
cub
'
)
.
field
(
'
MIN(cub.ano_censo)
'
,
'
start_year
'
)
.
field
(
'
MAX(cub.ano_censo)
'
,
'
end_year
'
);
next
();
},
query
,
response
(
'
range
'
));
cubApp
.
get
(
'
/years
'
,
(
req
,
res
,
next
)
=>
{
req
.
sql
.
from
(
'
cub
'
)
.
field
(
'
DISTINCT cub.ano_censo
'
,
'
year
'
);
next
();
},
query
,
response
(
'
years
'
));
cubApp
.
get
(
'
/months
'
,
(
req
,
res
,
next
)
=>
{
req
.
sql
.
from
(
'
cub
'
)
.
field
(
'
DISTINCT cub.mes_censo
'
,
'
month
'
);
next
();
},
query
,
response
(
'
months
'
));
cubApp
.
get
(
'
/years_months
'
,
(
req
,
res
,
next
)
=>
{
req
.
sql
.
from
(
'
cub
'
)
.
field
(
'
DISTINCT cub.ano_censo AS "year", cub.mes_censo AS "month"
'
);
next
();
},
query
,
response
(
'
years_months
'
));
cubApp
.
get
(
'
/price_type
'
,
(
req
,
res
,
next
)
=>
{
req
.
sql
.
from
(
'
cub
'
)
.
field
(
'
DISTINCT cub.tipo_preco
'
,
'
price_type
'
);
next
();
},
query
,
response
(
'
price_type
'
));
rqf
.
addField
({
name
:
'
filter
'
,
field
:
false
,
where
:
true
}).
addField
({
name
:
'
dims
'
,
field
:
true
,
where
:
false
}).
addValue
({
name
:
'
state
'
,
table
:
'
estado
'
,
tableField
:
[
'
sigla
'
,
'
id
'
],
resultField
:
[
'
sigla_uf
'
,
'
cod_uf
'
],
where
:
{
relation
:
'
=
'
,
type
:
'
integer
'
,
field
:
'
estado_id
'
,
table
:
'
cub
'
},
join
:
{
primary
:
'
id
'
,
foreign
:
'
estado_id
'
,
foreignTable
:
'
cub
'
}
}).
addValue
({
name
:
'
min_year
'
,
table
:
'
cub
'
,
tableField
:
'
ano_censo
'
,
resultField
:
'
year
'
,
where
:
{
relation
:
'
>=
'
,
type
:
'
integer
'
,
table
:
'
cub
'
,
field
:
'
ano_censo
'
}
}).
addValue
({
name
:
'
max_year
'
,
table
:
'
cub
'
,
tableField
:
'
ano_censo
'
,
resultField
:
'
year
'
,
where
:
{
relation
:
'
<=
'
,
type
:
'
integer
'
,
table
:
'
cub
'
,
field
:
'
ano_censo
'
}
}).
addValue
({
name
:
'
min_month
'
,
table
:
'
cub
'
,
tableField
:
'
mes_censo
'
,
resultField
:
'
month
'
,
where
:
{
relation
:
'
>=
'
,
type
:
'
integer
'
,
table
:
'
cub
'
,
field
:
'
mes_censo
'
}
}).
addValue
({
name
:
'
max_month
'
,
table
:
'
cub
'
,
tableField
:
'
mes_censo
'
,
resultField
:
'
month
'
,
where
:
{
relation
:
'
<=
'
,
type
:
'
integer
'
,
table
:
'
cub
'
,
field
:
'
mes_censo
'
}
});
cubApp
.
get
(
'
/
'
,
rqf
.
parse
(),
rqf
.
build
(),
(
req
,
res
,
next
)
=>
{
req
.
sql
.
from
(
'
cub
'
)
.
field
(
'
cub.estado_id
'
,
'
cod_uf
'
)
.
field
(
'
estado.sigla
'
,
'
sigla_uf
'
)
.
field
(
'
cub.tipo_preco
'
,
'
tipo_preco
'
)
.
field
(
'
cub.preco
'
,
'
preco
'
)
.
join
(
'
estado
'
,
null
,
'
cub.estado_id=estado.id
'
)
.
group
(
'
cub.ano_censo
'
)
.
group
(
'
cub.mes_censo
'
)
.
group
(
'
cub.estado_id
'
)
.
group
(
'
estado.sigla
'
)
.
group
(
'
cub.tipo_preco
'
)
.
group
(
'
cub.preco
'
)
next
();
},
query
,
addMissing
(
rqf
),
id2str
.
transform
(),
response
(
'
cub
'
));
module
.
exports
=
cubApp
;
This diff is collapsed.
Click to expand it.
src/test/cub.js
0 → 100644
+
109
−
0
View file @
fe90fbc3
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 cub
'
,
()
=>
{
it
(
'
should return default query cub
'
,
(
done
)
=>
{
chai
.
request
(
server
)
.
get
(
'
/api/v1/cub
'
)
.
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
(
'
cod_uf
'
);
res
.
body
.
result
[
0
].
should
.
have
.
property
(
'
sigla_uf
'
);
res
.
body
.
result
[
0
].
should
.
have
.
property
(
'
tipo_preco
'
);
res
.
body
.
result
[
0
].
should
.
have
.
property
(
'
preco
'
);
done
();
});
});
it
(
'
should list the years
'
,
(
done
)
=>
{
chai
.
request
(
server
)
.
get
(
'
/api/v1/cub/years
'
)
.
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
(
'
year
'
);
done
();
});
});
it
(
'
should list the year range
'
,
(
done
)
=>
{
chai
.
request
(
server
)
.
get
(
'
/api/v1/cub/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 the months
'
,
(
done
)
=>
{
chai
.
request
(
server
)
.
get
(
'
/api/v1/cub/months
'
)
.
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
(
'
month
'
);
done
();
});
});
it
(
'
should list the years and months
'
,
(
done
)
=>
{
chai
.
request
(
server
)
.
get
(
'
/api/v1/cub/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
(
'
year
'
);
res
.
body
.
result
[
0
].
should
.
have
.
property
(
'
month
'
);
done
();
});
});
it
(
'
should list the price type
'
,
(
done
)
=>
{
chai
.
request
(
server
)
.
get
(
'
/api/v1/cub/price_type
'
)
.
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
(
'
price_type
'
);
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