-
Notifications
You must be signed in to change notification settings - Fork 0
/
servercontroller.txt
46 lines (42 loc) · 1.17 KB
/
servercontroller.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const Pet = require("../models/pet.model.js");
module.exports= {
createPet: (req,res) =>{
Pet.create(req.body)
.then((newPet)=>res.json(newPet))
.catch((err) => console.log(err));
},
getAllPets: (req,res) => {
Pet.find({})
.then ((allPets)=>{
console.log(allPets);
res.json(allPets);
})
.catch ((err) => console.log(err))
},
getOnePet: (req,res) => {
Pet.findOne({_id: req.params.id})
.then ((onePet) =>{
console.log(onePet);
res.json(onePet);
})
.catch ((err) => console.log(err))
},
updatePet: (req, res) => {
Pet.findOneAndUpdate({_id: req.params.id},req.body,
{new: true , runValidators: true }
)
.then((updatedPet)=>{
console.log(updatedPet);
res.json(updatedPet);
})
.catch((err)=> console.log(err))
},
deletePet: (req,res)=>{
Pet.deleteOne({_id: req.params.id})
.then ((deletedPet)=>{
console.log(deletedPet);
res.json(deletedPet);
})
.catch((err)=> console.log(err))
}
};