Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
LDE API
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
simcaq
LDE API
Commits
5b13bb59
Commit
5b13bb59
authored
May 23, 2017
by
Vytor Calixto
👾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add indictor route
parent
127b9973
Pipeline
#9796
failed with stage
in 3 minutes and 50 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
2 deletions
+82
-2
src/libs/models/indicator.js
src/libs/models/indicator.js
+3
-2
src/libs/routes/api.js
src/libs/routes/api.js
+3
-0
src/libs/routes/indicator.js
src/libs/routes/indicator.js
+76
-0
No files found.
src/libs/models/indicator.js
View file @
5b13bb59
...
...
@@ -7,7 +7,7 @@ const Filters = require(`${libs}/models/filters`);
// set up a mongoose model
var
IndicatorSchema
=
new
Schema
({
filters
:
{
type
:
[
Schema
.
t
ypes
.
ObjectId
],
type
:
[
Schema
.
T
ypes
.
ObjectId
],
ref
:
'
Filters
'
},
name
:
{
...
...
@@ -38,7 +38,8 @@ var IndicatorSchema = new Schema({
required
:
true
},
noSchools
:
{
type
:
Boolean
type
:
Boolean
,
default
:
false
}
});
...
...
src/libs/routes/api.js
View file @
5b13bb59
...
...
@@ -12,11 +12,14 @@ const user = require(`${libs}/routes/user`);
const
message
=
require
(
`
${
libs
}
/routes/message
`
);
const
indicator
=
require
(
`
${
libs
}
/routes/indicator
`
);
api
.
get
(
'
/
'
,
(
req
,
res
)
=>
{
res
.
json
({
msg
:
'
SimCAQ API is running
'
});
});
api
.
use
(
'
/user
'
,
user
);
api
.
use
(
'
/message
'
,
message
);
api
.
use
(
'
/indicator
'
,
indicator
);
module
.
exports
=
api
;
src/libs/routes/indicator.js
0 → 100644
View file @
5b13bb59
const
express
=
require
(
'
express
'
);
const
indicatorApp
=
express
();
const
libs
=
`
${
process
.
cwd
()}
/libs
`
;
const
config
=
require
(
`
${
libs
}
/config
`
);
const
log
=
require
(
`
${
libs
}
/log
`
)(
module
);
const
Indicator
=
require
(
`
${
libs
}
/models/indicator
`
);
indicatorApp
.
get
(
'
/
'
,
(
req
,
res
,
next
)
=>
{
Indicator
.
find
((
err
,
indicators
)
=>
{
if
(
err
)
{
res
.
status
(
500
).
json
({
error
:
'
Erro do servidor
'
,
text
:
'
O servidor encontrou um erro ao processar a requisição
'
,
err
});
}
res
.
json
(
indicators
);
});
});
indicatorApp
.
put
(
'
/:id
'
,
(
req
,
res
,
next
)
=>
{
Indicator
.
findById
(
req
.
params
.
id
,
(
err
,
indicator
)
=>
{
if
(
!
indicator
)
{
res
.
status
(
404
).
json
({
error
:
'
Não encontrado
'
,
text
:
'
Nenhum indicador foi encontrado
'
,
err
});
}
if
(
!
err
)
{
indicator
.
name
=
req
.
body
.
name
|
indicator
.
name
;
indicator
.
url
=
req
.
body
.
url
|
indicator
.
url
;
indicator
.
active
=
req
.
body
.
active
|
indicator
.
active
;
indicator
.
description
=
req
.
body
.
description
|
indicator
.
description
;
indicator
.
route
=
req
.
body
.
route
|
indicator
.
route
;
indicator
.
source
=
req
.
body
.
source
|
indicator
.
source
;
indicator
.
noSchools
=
req
.
body
.
noSchools
|
indicator
.
noSchools
;
indicator
.
save
((
err
)
=>
{
if
(
err
)
{
res
.
status
(
500
).
json
({
error
:
'
Erro do servidor
'
,
text
:
'
O servidor encontrou um erro ao processar a requisição
'
,
err
});
}
res
.
json
(
indicator
);
});
}
else
{
res
.
status
(
500
).
json
({
error
:
'
Erro do servidor
'
,
text
:
'
O servidor encontrou um erro ao processar a requisição
'
,
err
});
}
});
});
indicatorApp
.
post
(
'
/
'
,
(
req
,
res
,
next
)
=>
{
req
.
checkBody
(
'
name
'
,
'
Nome é um campo obrigatório
'
).
notEmpty
();
req
.
checkBody
(
'
url
'
,
'
A url é um campo obrigatório
'
).
notEmpty
();
req
.
checkBody
(
'
route
'
,
'
A rota é um campo obrigatório
'
).
notEmpty
();
req
.
checkBody
(
'
source
'
,
'
A fonte é um campo obrigatório
'
).
notEmpty
();
req
.
getValidationResult
().
then
(
function
(
result
)
{
if
(
!
result
.
isEmpty
())
{
res
.
status
(
400
).
send
({
errors
:
result
.
array
()});
return
;
}
let
indicator
=
new
Indicator
({
name
:
req
.
body
.
name
,
url
:
req
.
body
.
url
,
active
:
req
.
body
.
url
,
description
:
req
.
body
.
description
,
route
:
req
.
body
.
route
,
source
:
req
.
body
.
source
,
noSchools
:
req
.
body
.
noSchools
});
indicator
.
save
((
err
)
=>
{
if
(
err
)
{
res
.
status
(
500
).
json
({
error
:
'
Erro do servidor
'
,
text
:
'
O servidor encontrou um erro ao processar a requisição
'
,
err
});
}
res
.
json
(
indicator
);
});
});
});
module
.
exports
=
indicatorApp
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment