Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
VILLASweb-backend-node
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
ACS
Public
VILLASframework
VILLASweb-backend-node
Commits
a1ca4436
Commit
a1ca4436
authored
7 years ago
by
Markus Grigull
Browse files
Options
Downloads
Patches
Plain Diff
Add node model and route
parent
2543ebd4
Branches
Branches containing commit
No related tags found
1 merge request
!7
Feature change simulator connection
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
config.js
+1
-1
1 addition, 1 deletion
config.js
models/node.js
+59
-0
59 additions, 0 deletions
models/node.js
routes/nodes.js
+114
-0
114 additions, 0 deletions
routes/nodes.js
server.js
+2
-0
2 additions, 0 deletions
server.js
with
176 additions
and
1 deletion
config.js
+
1
−
1
View file @
a1ca4436
...
...
@@ -26,7 +26,7 @@ module.exports = {
databaseURL
:
'
mongodb://localhost:27017/
'
,
port
:
4000
,
secret
:
'
longsecretislong
'
,
logLevel
:
'
verbose
'
,
// possible values: error, warn, info, verbose or debug
logLevel
:
'
debug
'
,
// possible values: error, warn, info, verbose or debug
logFile
:
'
log.txt
'
,
admin
:
{
username
:
'
admin
'
,
...
...
This diff is collapsed.
Click to expand it.
models/node.js
0 → 100644
+
59
−
0
View file @
a1ca4436
/**
* File: node.js
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
* Date: 21.06.2017
*
* This file is part of VILLASweb-backend.
*
* VILLASweb-backend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VILLASweb-backend is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VILLASweb-backend. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
// include
var
mongoose
=
require
(
'
mongoose
'
);
var
Simulator
=
require
(
'
./simulator
'
);
var
logger
=
require
(
'
../utils/logger
'
);
var
Schema
=
mongoose
.
Schema
;
// node model
var
nodeSchema
=
new
Schema
({
name
:
{
type
:
String
,
required
:
true
,
unique
:
true
},
endpoint
:
{
type
:
String
,
required
:
true
,
unique
:
true
},
config
:
{
type
:
Schema
.
Types
.
Mixed
,
default
:
{}
},
simulators
:
[{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
'
Simulator
'
,
default
:
[]
}]
});
nodeSchema
.
pre
(
'
remove
'
,
function
(
callback
)
{
// delete all simulators belonging to this node
this
.
simulators
.
forEach
(
function
(
id
)
{
Simulator
.
findOne
({
_id
:
id
},
function
(
err
,
simulator
)
{
if
(
err
)
{
logger
.
error
(
'
Unable to find simulator for id:
'
+
id
,
err
);
return
;
}
simulator
.
remove
(
function
(
err
)
{
if
(
err
)
{
logger
.
error
(
'
Unable to remove simulator
'
,
{
err
,
simulator
});
return
;
}
});
});
});
callback
();
});
module
.
exports
=
mongoose
.
model
(
'
Node
'
,
nodeSchema
);
This diff is collapsed.
Click to expand it.
routes/nodes.js
0 → 100644
+
114
−
0
View file @
a1ca4436
/**
* File: nodes.js
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
* Date: 21.06.2017
*
* This file is part of VILLASweb-backend.
*
* VILLASweb-backend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VILLASweb-backend is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VILLASweb-backend. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
// include
var
express
=
require
(
'
express
'
);
var
logger
=
require
(
'
../utils/logger
'
);
// models
var
Node
=
require
(
'
../models/node
'
);
// create router
var
router
=
express
.
Router
();
// routes
router
.
get
(
'
/nodes
'
,
function
(
req
,
res
)
{
// get all nodes
Node
.
find
(
function
(
err
,
nodes
)
{
if
(
err
)
{
logger
.
error
(
'
Unable to receive nodes
'
,
err
);
return
res
.
status
(
400
).
send
(
err
);
}
res
.
send
({
nodes
:
nodes
});
});
});
router
.
post
(
'
/nodes
'
,
function
(
req
,
res
)
{
// create new node
var
node
=
new
Simulator
(
req
.
body
.
node
);
node
.
save
(
function
(
err
)
{
if
(
err
)
{
logger
.
error
(
'
Unable to create node
'
,
err
);
return
res
.
status
(
400
).
send
(
err
);
}
res
.
send
({
node
:
node
});
});
});
router
.
put
(
'
/nodes/:id
'
,
function
(
req
,
res
)
{
// get node
Node
.
findOne
({
_id
:
req
.
params
.
id
},
function
(
err
,
node
)
{
if
(
err
)
{
logger
.
log
(
'
verbose
'
,
'
PUT Unknown node for id:
'
+
req
.
params
.
id
);
return
res
.
status
(
400
).
send
(
err
);
}
// update all properties
for
(
property
in
req
.
body
.
node
)
{
node
[
property
]
=
req
.
body
.
node
[
property
];
}
// save the changes
node
.
save
(
function
(
err
)
{
if
(
err
)
{
logger
.
error
(
'
Unable to save node
'
,
node
);
return
res
.
status
(
500
).
send
(
err
);
}
res
.
send
({
node
:
node
});
});
});
});
router
.
get
(
'
/nodes/:id
'
,
function
(
req
,
res
)
{
Node
.
findOne
({
_id
:
req
.
params
.
id
},
function
(
err
,
node
)
{
if
(
err
)
{
logger
.
log
(
'
verbose
'
,
'
GET Unknown node for id:
'
+
req
.
params
.
id
);
return
res
.
status
(
400
).
send
(
err
);
}
res
.
send
({
node
:
node
});
});
});
router
.
delete
(
'
/nodes/:id
'
,
function
(
req
,
res
)
{
Node
.
findOne
({
_id
:
req
.
params
.
id
},
function
(
err
,
node
)
{
if
(
err
)
{
logger
.
log
(
'
verbose
'
,
'
DELETE Unknown node for id:
'
+
req
.
params
.
id
);
return
res
.
status
(
400
).
send
(
err
);
}
node
.
remove
(
function
(
err
)
{
if
(
err
)
{
logger
.
error
(
'
Unable to remove node
'
,
node
);
return
res
.
status
(
500
).
send
(
err
);
}
res
.
send
({});
});
});
});
module
.
exports
=
router
;
This diff is collapsed.
Click to expand it.
server.js
+
2
−
0
View file @
a1ca4436
...
...
@@ -38,6 +38,7 @@ var simulationModels = require('./routes/simulationModels');
var
simulators
=
require
(
'
./routes/simulators
'
);
var
upload
=
require
(
'
./routes/upload
'
);
var
files
=
require
(
'
./routes/files
'
);
var
nodes
=
require
(
'
./routes/nodes
'
);
var
User
=
require
(
'
./models/user
'
);
...
...
@@ -93,6 +94,7 @@ app.use('/api/v1', simulationModels);
app
.
use
(
'
/api/v1
'
,
simulators
);
app
.
use
(
'
/api/v1
'
,
upload
);
app
.
use
(
'
/api/v1
'
,
files
);
app
.
use
(
'
/api/v1
'
,
nodes
);
app
.
use
(
'
/public
'
,
express
.
static
(
__dirname
+
'
/public
'
));
...
...
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