Controller and Model updates
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
const { CommentService } = require('../services');
|
||||
const asyncHandler = require("../middlewares/asyncHandler");
|
||||
const ErrorResponse = require("../utils/errorResponse");
|
||||
|
||||
module.exports.createComment = asyncHandler(async (req, res, next) => {
|
||||
try {
|
||||
const { slug, title, description, body, authorId } = req.body;
|
||||
const comment = await CommentService.createComment({
|
||||
slug,
|
||||
title,
|
||||
description,
|
||||
body,
|
||||
authorId
|
||||
});
|
||||
|
||||
res.status(201).json({
|
||||
message: 'Comment created successfully.',
|
||||
data: comment,
|
||||
});
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while creating comment.', 500, err.message));
|
||||
}
|
||||
});
|
||||
|
||||
module.exports.getAllComments = asyncHandler(async (req, res, next) => {
|
||||
try {
|
||||
const comments = await CommentService.getAllComments();
|
||||
|
||||
res.status(200).json({
|
||||
data: comments,
|
||||
});
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while fetching comments.', 500, err.message));
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user