mirror of
https://github.com/Exp-Primer-Copilot-Cohort-1/experience-primer-copilot-exituser.git
synced 2026-09-17 04:18:57 +00:00
asd
This commit is contained in:
+31
@@ -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,
|
||||||
Reference in New Issue
Block a user