Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
IcarusServer
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
icarus
IcarusServer
Commits
e67c00c4
Commit
e67c00c4
authored
Nov 27, 2015
by
andreagerino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
d6aa6c0c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
56 deletions
+30
-56
storage.js
routes/storage.js
+30
-56
No files found.
routes/storage.js
View file @
e67c00c4
...
...
@@ -11,19 +11,22 @@ var assert = assert = require('assert');
var
mongoUrl
=
'mongodb://icarus:icarus@localhost:27017/icarus'
;
//Use connect method to test the connection to the Server
var
mongo
Db
;
var
icarus
Db
;
mongoClient
.
connect
(
mongoUrl
,
function
(
err
,
db
)
{
assert
.
equal
(
null
,
err
,
err
);
debug
(
"Connected to MongoDB database: "
+
db
.
databaseName
);
mongo
Db
=
db
;
icarus
Db
=
db
;
});
router
.
get
(
'/:resource_id'
,
function
(
req
,
res
,
next
)
{
mongoClient
.
connect
(
mongoUrl
,
function
(
err
,
db
)
{
var
collection
=
icarusDb
.
collection
(
'resources'
);
var
_id
=
new
ObjectID
(
req
.
params
.
resource_id
);
collection
.
find
({
"_id"
:
_id
}).
limit
(
1
).
next
(
function
(
err
,
doc
){
if
(
err
!=
null
){
...
...
@@ -32,31 +35,15 @@ router.get('/:resource_id', function(req, res, next) {
}
else
{
var
collection
=
db
.
collection
(
'resources'
);
var
_id
=
new
ObjectID
(
req
.
params
.
resource_id
);
collection
.
find
({
"_id"
:
_id
}).
limit
(
1
).
next
(
function
(
err
,
doc
){
if
(
err
!=
null
){
debug
(
err
);
next
(
err
);
}
else
{
if
(
doc
==
undefined
){
res
.
sendStatus
(
404
);
if
(
doc
==
undefined
){
}
else
{
res
.
sendStatus
(
404
);
res
.
send
(
doc
);
}
}
else
{
}
res
.
send
(
doc
);
}
);
}
}
...
...
@@ -66,50 +53,37 @@ router.get('/:resource_id', function(req, res, next) {
router
.
post
(
'/'
,
function
(
req
,
res
,
next
){
mongoClient
.
connect
(
mongoUrl
,
function
(
err
,
db
)
{
if
(
err
!=
null
){
debug
(
err
);
next
(
err
);
}
else
{
var
collection
=
db
.
collection
(
'resources'
);
var
resource
=
req
.
body
;
if
(
Object
.
keys
(
resource
).
length
>
0
)
{
collection
.
insertOne
(
resource
,
function
(
err
,
r
)
{
var
collection
=
icarusDb
.
collection
(
'resources'
);
var
resource
=
req
.
body
;
if
(
err
!=
null
)
{
if
(
Object
.
keys
(
resource
).
length
>
0
)
{
debug
(
err
);
next
(
err
);
collection
.
insertOne
(
resource
,
function
(
err
,
r
)
{
}
else
{
if
(
err
!=
null
)
{
res
.
statusCode
=
201
;
res
.
send
({
"_id"
:
r
.
insertedId
}
);
debug
(
err
)
;
next
(
err
);
}
}
else
{
});
res
.
statusCode
=
201
;
res
.
send
({
"_id"
:
r
.
insertedId
});
}
else
{
}
var
error
=
new
Error
(
"You can't store an empty resource!"
);
error
.
status
=
400
;
});
debug
(
error
);
next
(
error
);
}
else
{
}
var
error
=
new
Error
(
"You can't store an empty resource!"
);
error
.
status
=
400
;
}
debug
(
error
);
next
(
error
);
}
);
}
}
);
}
module
.
exports
=
router
;
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