Skip to content

Commit

Permalink
Merge pull request #28 from AlixH/plugin-comment-back
Browse files Browse the repository at this point in the history
#19 - Système commentaires Back
  • Loading branch information
chihabeddine-aourinmouche authored Feb 20, 2020
2 parents 15ab7f7 + 793098d commit be22637
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
38 changes: 38 additions & 0 deletions back-end/server/controller/PluginController.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,42 @@ module.exports = {
}
});
},

/**
* Get plugin's score
*/
comment: (req, res, next) => {
console.log(">>> comment <<<");

let pluginId = req.body.pluginId;
let commentText = req.body.commentText;

Plugin.findOne({_id: pluginId}, (err, plugin) => {
if(err){
next(err);
} else{
let comments = plugin.comments;
comments.push(commentText);
Plugin.updateOne({_id: plugin._id}, {comments: comments}, (error, p) => {
if(error){
next(error);
} else{
res.json({status: "Success", message: `Comment ${commentText} has been added to plugin ${plugin.name}`, data: null});
}
});
}
});
},
};

/**
* Echapper les caractères spéciaux HTML
*/
let escapeHtml = (unsafe) => {
return unsafe
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
};
1 change: 1 addition & 0 deletions back-end/server/routes/PluginRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ module.exports = (Application) => {
Application.route('/plugins/:pluginId').delete(Controller.PluginController.deleteById);
Application.route('/plugins/rate').post(Controller.PluginController.rate);
Application.route('/plugins/get-score').post(Controller.PluginController.getScore);
Application.route('/plugins/comment').post(Controller.PluginController.comment);
};

0 comments on commit be22637

Please sign in to comment.