Skip to content
Snippets Groups Projects
Commit 6d05e389 authored by Talty-Kerr, Patrick (UG - Comp Sci & Elec Eng)'s avatar Talty-Kerr, Patrick (UG - Comp Sci & Elec Eng)
Browse files

added response 404 to get request

parent 50cac579
No related branches found
No related tags found
1 merge request!13Create Comment service requirements
......@@ -78,16 +78,38 @@ const createComment = async ( req: Request, res: Response, next: NextFunction,)
} catch (error) {
return res.status(400).json({ message: 'Bad Request' });
return res.status(400).send({ message: 'Bad Request' });
}
};
const readAllComments = async (req: Request, res: Response, next: NextFunction) => {
//400
//401
//403
const id = req.params.post_id;
console.log(id)
try{
const posts = {post_id : new mongoose.Types.ObjectId(id)}
const post_exist = await Comment.countDocuments(posts, { limit: 1 })
if(post_exist == 0) {
return res.status(404).send({message: 'Specified Post Not Found.'});
}
}
catch{
return res.status(404).send({message: 'Specified Post Not Found.'});
}
try {
const query = {post_id : new mongoose.Types.ObjectId(id)}
const comments = await Comment.find(query).limit(50)
//const comments: object[] = await Comment.find({}, { _id: 1 }).toArray()
......
......@@ -4,7 +4,7 @@ import controller from '../controllers/Comment';
const router = express.Router();
router.post('/create', controller.createComment);
router.get('/get/:post_id', controller.readAllComments);
router.get('/:post_id', controller.readAllComments);
export = router;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment