Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
daa-custom-stack
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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Felipe Vieira de Moraes Tavares
daa-custom-stack
Commits
8e9a7be3
Commit
8e9a7be3
authored
Feb 14, 2017
by
nemoNoboru
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added new pet. remove pet breaks dont know why
parent
011fa5ef
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
8 deletions
+42
-8
index.js
backend/app/index.js
+26
-6
people.js
backend/app/people/people.js
+16
-2
No files found.
backend/app/index.js
View file @
8e9a7be3
...
...
@@ -16,6 +16,14 @@ app.use(cors())
var
people_path
=
'/people'
function
end
(
res
,
err
)
{
if
(
err
)
{
return
res
.
status
(
500
).
send
(
err
)
}
else
{
res
.
send
(
"ok"
)
}
}
app
.
get
(
people_path
,
function
(
req
,
res
)
{
people
.
index
(
function
(
err
,
people
)
{
res
.
send
(
people
)
...
...
@@ -24,20 +32,32 @@ app.get(people_path,function (req,res) {
app
.
post
(
people_path
,
function
(
req
,
res
)
{
var
person_name
=
req
.
body
.
name
people
.
create
(
person_name
,
function
(
err
)
{
res
.
send
(
err
)
people
.
create
(
person_name
,
function
(
err
)
{
end
(
res
,
err
)
})
})
app
.
put
(
people_path
+
"/:person_id"
,
function
(
req
,
res
)
{
people
.
modify
(
req
.
params
.
person_id
,
req
.
body
.
name
,
function
(
err
)
{
res
.
send
(
err
)
people
.
modify
(
req
.
params
.
person_id
,
req
.
body
.
name
,
function
(
err
)
{
end
(
res
,
err
)
})
})
app
.
delete
(
people_path
+
"/:person_id"
,
function
(
req
,
res
)
{
people
.
remove
(
req
.
params
.
person_id
,
function
(
err
)
{
res
.
send
(
err
)
people
.
remove
(
req
.
params
.
person_id
,
function
(
err
)
{
end
(
res
,
err
)
})
})
app
.
post
(
people_path
+
"/pets"
,
function
(
req
,
res
)
{
people
.
addPet
(
req
.
body
.
id
,
req
.
body
.
petname
,
function
(
err
)
{
end
(
res
,
err
)
})
})
app
.
delete
(
people_path
+
"/pets"
,
function
(
req
,
res
)
{
people
.
removePet
(
req
.
body
.
id
,
req
.
body
.
petname
,
function
(
err
)
{
end
(
res
,
err
)
})
})
...
...
backend/app/people/people.js
View file @
8e9a7be3
...
...
@@ -4,10 +4,10 @@ var mongoose = require('mongoose')
var
people
=
{}
db
.
once
(
'open'
,
function
()
{
people
.
model
=
mongoose
.
model
(
'People'
,{
name
:
String
})
people
.
model
=
mongoose
.
model
(
'People'
,{
name
:
String
,
pets
:
Array
})
people
.
index
=
function
(
callback
)
{
people
.
model
.
find
({},
'name'
,
callback
)
people
.
model
.
find
({},
callback
)
}
people
.
create
=
function
(
personName
,
callback
)
{
...
...
@@ -26,6 +26,20 @@ db.once('open',function () {
people
.
model
.
findById
(
id
).
remove
(
callback
)
}
people
.
addPet
=
function
(
id
,
pet_name
,
callback
)
{
people
.
model
.
findById
(
id
).
then
(
function
(
person
)
{
person
.
pets
.
push
(
pet_name
)
person
.
save
(
callback
)
})
}
people
.
removePet
=
function
(
id
,
pet_name
,
callback
)
{
people
.
model
.
findById
(
id
).
then
(
function
(
person
)
{
person
.
pets
.
remove
(
pet_name
)
person
.
save
(
callback
)
})
}
})
module
.
exports
=
people
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