-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaffirmations.js
39 lines (33 loc) · 1.32 KB
/
affirmations.js
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
const Affirmation = require("../../models/affirmation");
module.exports = {
index,
show,
create,
delete: deleteOne,
update
};
// setting all affirmations to variable and turning variable into JSON
async function index(req, res) {
const affirmations = await Affirmation.find({})
res.status(200).json(affirmations)
};
// finding individual affirmation by id and set it to a variable that turns into a json obj
async function show(req, res){
const affirmation = await Affirmation.findById(req.params.id)
res.status(200).json(affirmation)
}
// creating a affirmation from req body, setting to affirmation variable, turning variable into json obj
async function create(req,res){
const affirmation = await Affirmation.create(req.body)
res.status(201).json(affirmation)
}
// deleting affirmation by id, and setting to variable, and turning variable into a json obj
async function deleteOne(req,res){
const deletedAffirmation = await Affirmation.findByIdAndRemove(req.params.id)
res.status(200).json(deletedAffirmation)
}
// updating affirmation by id to req body, setting to variable, turning variable into json obj
async function update(req,res){
const updatedAffirmation = await Affirmation.findByIdAndUpdate(req.params.id, req.body, {new: true})
res.status(200).json(updatedAffirmation)
}