-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathgetAllPosts.js
More file actions
34 lines (23 loc) · 690 Bytes
/
getAllPosts.js
File metadata and controls
34 lines (23 loc) · 690 Bytes
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
/**
* @module Get All Posts Controller
*
* @param {Request} req - HTTP Request from the client
* @param {Response} res - HTTP Response for the client
*
* @description
* This controller allows to read a all the existing posts, if all parameters are correct.
*
* @todo
* Nothing for now.
*/
module.exports.getAllPosts = async (req, res) => {
// fetch all the posts.
const foundPosts = await Post.findAll({
attributes: ['title', 'content'],
})
if (!foundPosts || !foundPosts.length ) {
return res.status(404).send('No posts for now.');
}
// send back to the user the fetched data.
return res.status(200).json(foundPosts);
}