Created
April 18, 2019 08:58
-
-
Save Fiyiin/5dc05e7200513784ffeb5fb23eff680c to your computer and use it in GitHub Desktop.
this is quite painful
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* middleware to get all reported comments | |
* @static | |
* @param {Request} req request object | |
* @param {Response} res response object | |
* @param {Function} next called on server errors | |
* @returns {void} void | |
* @memberof ReportedComments | |
*/ | |
static async getReported(req, res, next) { | |
try { | |
let comments = await sequelize.query(`WITH allcomments AS (SELECT id as tracker, author, "articleId", body, "parentTracker", "createdAt" FROM comments | |
UNION ALL SELECT tracker, author, "articleId", body, "parentTracker", "createdAt" FROM "archivedComments" ORDER BY "createdAt") | |
SELECT id, userid, reason, allcomments.* FROM "reportedComments" LEFT JOIN allcomments ON "reportedComments".commentid = allcomments.tracker | |
WHERE id = $1`, { | |
bind: [req.params.reportedId], | |
type: sequelize.QueryTypes.SELECT | |
}); | |
let reason; | |
let userid; | |
let id; | |
comments = comments.map((comment) => { | |
id = comment.id | |
reason = comment.reason; | |
userid = comment.userid; | |
delete comment.reason; | |
delete comment.userid; | |
delete comment.id; | |
return comment; | |
}) | |
res.status(200).send({ status: 200, id, userid, reason, comments }); | |
} catch (error) { | |
console.log(error) | |
next(error); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment