Skip to content

Commit

Permalink
Merge 90322f2 into fa7d3ab
Browse files Browse the repository at this point in the history
  • Loading branch information
vic3king committed May 6, 2019
2 parents fa7d3ab + 90322f2 commit f7525cd
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 34 deletions.
47 changes: 14 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 26 additions & 1 deletion server/controllers/get-articles.controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ const getArticles = async (req, res) => {
'slug',
'title',
'body',
'likes_count',
'reading_time',
'category',
'createdAt',
'updatedAt',
'likes_count',
],
include: [
{
Expand Down Expand Up @@ -89,9 +91,32 @@ const getAllReportedArticles = async (req, res) => {
});
}
};

const getAllArticles = async (req, res) => {
try {
const articles = await Article.findAll({
include: [
{
model: User,
as: 'author',
attributes: ['first_name', 'last_name'],
},
],
});

return res.status(200).json({
articles,
});
} catch (error) {
return res.status(500).json({
errors: serverError(),
});
}
};
const Articles = {
getArticles,
getAllReportedArticles,
getAllArticles,
};

export default Articles;
22 changes: 22 additions & 0 deletions server/routes/get-articles.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,26 @@ router.get(
Articles.getAllReportedArticles
);

/**
* @swagger
*
* /reported-articles:
* get:
* tags:
* - article
* description: a verified reviewer can get all articles
* responses:
* 200:
* description: Success
* 400:
* description: Bad request
* 401:
* description: unauthorized
* 403:
* description: Forbidden
* 500:
* description: ran
*/
router.get('/articles', Articles.getAllArticles);

export default router;
4 changes: 4 additions & 0 deletions server/seeders/20190331211246-articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
likes_count: 23,
image_url: 'https://picsum.photos/200/300',
is_reported: false,
reading_time: 8,
},
{
id: 'fa3def47-153a-40bd-8181-a1c787e083d6',
Expand All @@ -30,6 +31,7 @@ module.exports = {
likes_count: 3244,
image_url: 'https://picsum.photos/200/300',
is_reported: false,
reading_time: 3,
},
{
id: 'fb3def47-153c-40bd-8161-a1c787e083d6',
Expand All @@ -45,6 +47,7 @@ module.exports = {
likes_count: 3244,
image_url: 'https://picsum.photos/200/300',
is_reported: false,
reading_time: 1,
},
{
id: 'fb3def47-153c-40bd-8161-a1c787e083d7',
Expand All @@ -60,6 +63,7 @@ module.exports = {
likes_count: 3244,
image_url: 'https://picsum.photos/200/300',
is_reported: false,
reading_time: 5,
},
]),
};
13 changes: 13 additions & 0 deletions tests/article-pagination.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,16 @@ describe('Display articles in pages', () => {
});
});
});

describe('Get all articles', () => {
it('should get all articles', done => {
chai
.request(app)
.get('/api/v1/articles')
.end((err, res) => {
expect(res).to.have.status(200);
expect(res.body.articles).to.be.a('array');
done();
});
});
});

0 comments on commit f7525cd

Please sign in to comment.