From ebf28a91c2e8fc7530581fc489b21306ff85e229 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 19 Dec 2023 14:50:19 +0000 Subject: [PATCH] asd --- comments.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 comments.js diff --git a/comments.js b/comments.js new file mode 100644 index 0000000..0b63ba9 --- /dev/null +++ b/comments.js @@ -0,0 +1,31 @@ +// Create web server + +// Import modules +const express = require('express'); +const router = express.Router(); +const Comment = require('../models/Comment'); + +// Get all comments +router.get('/', async (req, res) => { + try { + const comments = await Comment.find(); + res.json(comments); + } catch (err) { + res.json({ message: err }); + } +}); + +// Get comment by id +router.get('/:commentId', async (req, res) => { + try { + const comment = await Comment.findById(req.params.commentId); + res.json(comment); + } catch (err) { + res.json({ message: err }); + } +}); + +// Add comment +router.post('/', async (req, res) => { + const comment = new Comment({ + text: req.body.text, \ No newline at end of file