diff --git a/back-end/server/controller/PluginController.js b/back-end/server/controller/PluginController.js index b879a8a..62f7556 100644 --- a/back-end/server/controller/PluginController.js +++ b/back-end/server/controller/PluginController.js @@ -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, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'"); }; \ No newline at end of file diff --git a/back-end/server/routes/PluginRoutes.js b/back-end/server/routes/PluginRoutes.js index e166a83..bfda581 100644 --- a/back-end/server/routes/PluginRoutes.js +++ b/back-end/server/routes/PluginRoutes.js @@ -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); }; \ No newline at end of file