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
4d1a15d8
Commit
4d1a15d8
authored
7 years ago
by
Vytor Calixto
Browse files
Options
Downloads
Patches
Plain Diff
Change simulation routes
parent
a782dc34
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!116
Release v1.0.0
,
!90
Issue/347
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/libs/routes/simulation.js
+64
-109
64 additions, 109 deletions
src/libs/routes/simulation.js
with
64 additions
and
109 deletions
src/libs/routes/simulation.js
+
64
−
109
View file @
4d1a15d8
...
@@ -14,6 +14,8 @@ const response = require(`${libs}/middlewares/response`);
...
@@ -14,6 +14,8 @@ const response = require(`${libs}/middlewares/response`);
const
Simulation
=
require
(
`
${
libs
}
/models/simulation`
);
const
Simulation
=
require
(
`
${
libs
}
/models/simulation`
);
const
passport
=
require
(
'
passport
'
);
simulationApp
.
get
(
'
/time
'
,
(
req
,
res
,
next
)
=>
{
simulationApp
.
get
(
'
/time
'
,
(
req
,
res
,
next
)
=>
{
const
maxTime
=
parseInt
(
req
.
query
.
max_time
,
10
);
const
maxTime
=
parseInt
(
req
.
query
.
max_time
,
10
);
log
.
debug
(
'
maxTime:
'
,
maxTime
);
log
.
debug
(
'
maxTime:
'
,
maxTime
);
...
@@ -29,133 +31,86 @@ simulationApp.get('/time', (req, res, next) => {
...
@@ -29,133 +31,86 @@ simulationApp.get('/time', (req, res, next) => {
});
});
});
});
simulationApp
.
get
(
'
/
'
,
(
req
,
res
)
=>
{
simulationApp
.
get
(
'
/
'
,
passport
.
authenticate
(
'
bearer
'
,
{
session
:
false
}),
(
req
,
res
)
=>
{
let
out
=
{
success
:
true
,
msg
:
'
controller working
'
};
let
user
=
req
.
user
.
toObject
();
out
.
result
=
new
Array
()
Simulation
.
find
({
userId
:
user
.
_id
},
(
err
,
simulations
)
=>
{
Simulation
.
find
({},
function
(
err
,
sims
)
{
if
(
err
)
{
sims
.
forEach
((
sim
)
=>
{
log
.
error
(
err
);
out
.
result
.
push
(
sim
);
return
next
({
err
});
});
}
res
.
send
(
out
);
res
.
json
(
simulations
);
});
});
});
});
simulationApp
.
post
(
'
/
'
,
(
req
,
res
,
next
)
=>
{
simulationApp
.
post
(
'
/
'
,
passport
.
authenticate
(
'
bearer
'
,
{
session
:
false
}),
(
req
,
res
,
next
)
=>
{
// This method must associate new entry with user.
let
user
=
req
.
user
.
toObject
();
/* Creates a new simulation. Requires a name. */
if
(
!
req
.
body
.
name
)
{
let
simulation
=
new
Simulation
({
res
.
send
({
success
:
false
,
msg
:
'
Must send a name for new entry
'
});
userId
:
user
.
_id
,
}
else
{
content
:
req
.
body
.
content
next
();
}
},
(
req
,
res
)
=>
{
let
currentdate
=
new
Date
();
let
newSimulation
=
new
Simulation
({
name
:
req
.
body
.
name
,
timestamp
:
currentdate
.
getDate
(),
});
});
newSimulation
.
save
((
err
)
=>
{
if
(
err
)
{
simulation
.
save
((
err
)
=>
{
res
.
send
({
success
:
false
,
msg
:
err
});
if
(
err
)
{
}
else
{
log
.
error
(
err
);
res
.
send
({
return
next
({
err
});
success
:
true
,
msg
:
'
new sim created
'
,
id
:
newSimulation
.
_id
,
});
}
}
});
res
.
json
({
msg
:
'
Simulation created
'
});
})
});
});
simulationApp
.
get
(
'
/:id
'
,
(
req
,
res
)
=>
{
simulationApp
.
get
(
'
/:id
'
,
passport
.
authenticate
(
'
bearer
'
,
{
session
:
false
}),
(
req
,
res
)
=>
{
/* Can be used to check simulation construction status */
let
user
=
req
.
user
.
toObject
();
Simulation
.
findById
(
req
.
params
.
id
,
(
err
,
simulation
)
=>
{
log
.
debug
(
req
.
params
.
id
);
if
(
err
)
{
res
.
send
({
success
:
false
,
msg
:
err
});
return
;
}
if
(
!
simulation
)
{
Simulation
.
findOne
({
_id
:
req
.
params
.
id
,
userId
:
user
.
_id
},
(
err
,
simulation
)
=>
{
res
.
send
({
success
:
false
,
msg
:
'
Entry not found
'
});
if
(
err
)
{
}
else
{
log
.
error
(
err
);
re
s
.
send
(
simulation
);
re
turn
next
({
err
}
);
}
}
res
.
json
(
simulation
);
});
});
});
});
simulationApp
.
post
(
'
/:id
'
,
(
req
,
res
,
next
)
=>
{
simulationApp
.
put
(
'
/:id
'
,
passport
.
authenticate
(
'
bearer
'
,
{
session
:
false
}),
(
req
,
res
,
next
)
=>
{
if
(
!
Object
.
keys
(
req
.
body
).
length
)
{
let
user
=
req
.
user
.
toObject
();
res
.
send
({
success
:
false
,
msg
:
'
No field informed to update
'
});
}
else
{
Simulation
.
findOne
({
_id
:
req
.
params
.
id
,
userId
:
user
.
_id
},
(
err
,
simulation
)
=>
{
next
();
if
(
err
)
{
}
log
.
error
(
err
);
},
(
req
,
res
,
next
)
=>
{
return
next
({
err
});
let
simulation
=
Simulation
.
findById
(
req
.
params
.
id
,
(
err
,
simulation
)
=>
{
if
(
err
)
{
res
.
send
({
success
:
false
,
msg
:
err
});
}
else
{
if
(
!
simulation
)
{
res
.
send
({
success
:
false
,
msg
:
'
Entry not found
'
});
}
else
{
req
.
simulation
=
simulation
;
next
();
}
}
});
},
(
req
,
res
)
=>
{
for
(
let
property
in
req
.
body
)
{
if
(
Simulation
.
schema
.
tree
.
hasOwnProperty
(
property
))
{
if
(
!
req
.
simulation
.
update
(
property
,
req
.
body
[
property
])){
res
.
send
({
success
:
false
,
msg
:
'
Invalid format for
'
+
property
,
});
return
;
}
}
else
{
res
.
send
({
success
:
false
,
msg
:
'
Unknown property
'
+
property
,
});
return
;
}
}
}
req
.
simulation
.
save
((
err
)
=>
{
if
(
!
simulation
)
{
if
(
err
)
{
res
.
statusCode
=
404
;
res
.
send
({
success
:
false
,
msg
:
err
});
return
next
({
err
:
{
msg
:
'
Simulation not found
'
}});
}
else
{
res
.
send
({
success
:
true
,
msg
:
'
sim updated
'
,
id
:
req
.
simulation
.
_id
,
});
}
}
});
});
simulationApp
.
delete
(
'
/:id
'
,
(
req
,
res
,
next
)
=>
{
simulation
.
content
=
req
.
body
.
content
|
simulation
.
content
;
let
simulation
=
Simulation
.
findById
(
req
.
params
.
id
,
(
err
,
simulation
)
=>
{
if
(
err
)
{
simulation
.
save
((
err
)
=>
{
res
.
send
({
success
:
false
,
msg
:
err
});
if
(
err
)
{
}
else
{
log
.
error
(
err
);
if
(
!
simulation
)
{
return
next
(
err
);
res
.
send
({
success
:
false
,
msg
:
'
Entry not found
'
});
}
else
{
next
();
}
}
}
res
.
json
(
simulation
);
});
});
});
}
,
(
req
,
res
)
=>
{
}
);
Simulation
.
remove
({
"
_id
"
:
req
.
params
.
id
},
(
err
)
=>
{
if
(
err
)
{
simulationApp
.
delete
(
'
/:id
'
,
passport
.
authenticate
(
'
bearer
'
,
{
session
:
false
}),
(
req
,
res
,
next
)
=>
{
res
.
send
({
success
:
false
,
msg
:
err
}
);
let
user
=
req
.
user
.
toObject
(
);
}
else
{
res
.
send
(
{
Simulation
.
remove
({
_id
:
req
.
params
.
id
,
userId
:
user
.
_id
},
(
err
,
simulation
)
=>
{
success
:
true
,
if
(
err
)
{
msg
:
'
sim removed
'
,
log
.
error
(
err
);
});
return
next
({
err
});
}
}
res
.
json
({
msg
:
'
Simulation removed
'
});
});
});
});
});
...
...
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