Skip to content

Commit

Permalink
Bug(fix report article): fixed so that it can get article title
Browse files Browse the repository at this point in the history
- added article title in reported articles

[Delivers #166756694]
  • Loading branch information
blaisebakundukize committed Jun 18, 2019
1 parent 92b69ab commit cd99b5b
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions controllers/report/reportArticle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import models from '../../models/index';
import httpError from '../../helpers/errors/httpError';
import validate from '../../helpers/validateUser';

const { reportType, reportArticle } = models;
const { reportType, reportArticle, article } = models;
/**
* Controller for reporting article
* @exports
* @class
*/
class ArticleReport {
/**
* Create a new report type
* @param {object} req - Requests from user
* @param {object} res - Object that capture response
* @returns {object} Response
*/
/**
* Create a new report type
* @param {object} req - Requests from user
* @param {object} res - Object that capture response
* @returns {object} Response
*/
async createReportType(req, res) {
const { type } = req.body;
const validateType = validate.isEmpty(type);
Expand Down Expand Up @@ -78,7 +78,10 @@ class ArticleReport {
async getReportedArticles(req, res) {
const reportedArticles = await reportArticle.findAll({
attributes: ['id', 'articleId', 'reporter', 'comment'],
include: [{ model: reportType, attributes: ['id', 'type'] }]
include: [
{ model: reportType, attributes: ['id', 'type'] },
{ model: article, attributes: ['title'] }
]
});
if (reportedArticles.length === 0) throw new httpError(404, 'reported articles are not found.');
res.status(200).send(reportedArticles);
Expand Down

0 comments on commit cd99b5b

Please sign in to comment.