sanitized errors
This commit is contained in:
@@ -40,7 +40,7 @@ const buildCommentTree = (comments, isAdmin = false) => {
|
||||
};
|
||||
|
||||
// GET /api/forum/posts - Browse all posts
|
||||
router.get('/posts', optionalAuth, async (req, res) => {
|
||||
router.get('/posts', optionalAuth, async (req, res, next) => {
|
||||
try {
|
||||
const {
|
||||
search,
|
||||
@@ -158,12 +158,12 @@ router.get('/posts', optionalAuth, async (req, res) => {
|
||||
stack: error.stack,
|
||||
query: req.query
|
||||
});
|
||||
res.status(500).json({ error: error.message });
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/forum/posts/:id - Get single post with all comments
|
||||
router.get('/posts/:id', optionalAuth, async (req, res) => {
|
||||
router.get('/posts/:id', optionalAuth, async (req, res, next) => {
|
||||
try {
|
||||
const post = await ForumPost.findByPk(req.params.id, {
|
||||
include: [
|
||||
@@ -233,12 +233,12 @@ router.get('/posts/:id', optionalAuth, async (req, res) => {
|
||||
stack: error.stack,
|
||||
postId: req.params.id
|
||||
});
|
||||
res.status(500).json({ error: error.message });
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
// POST /api/forum/posts - Create new post
|
||||
router.post('/posts', authenticateToken, uploadForumPostImages, async (req, res) => {
|
||||
router.post('/posts', authenticateToken, uploadForumPostImages, async (req, res, next) => {
|
||||
try {
|
||||
let { title, content, category, tags, zipCode, latitude: providedLat, longitude: providedLng } = req.body;
|
||||
|
||||
@@ -481,12 +481,12 @@ router.post('/posts', authenticateToken, uploadForumPostImages, async (req, res)
|
||||
authorId: req.user.id,
|
||||
postData: logger.sanitize(req.body)
|
||||
});
|
||||
res.status(500).json({ error: error.message });
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
// PUT /api/forum/posts/:id - Update post
|
||||
router.put('/posts/:id', authenticateToken, async (req, res) => {
|
||||
router.put('/posts/:id', authenticateToken, async (req, res, next) => {
|
||||
try {
|
||||
const post = await ForumPost.findByPk(req.params.id);
|
||||
|
||||
@@ -549,12 +549,12 @@ router.put('/posts/:id', authenticateToken, async (req, res) => {
|
||||
postId: req.params.id,
|
||||
authorId: req.user.id
|
||||
});
|
||||
res.status(500).json({ error: error.message });
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
// DELETE /api/forum/posts/:id - Delete post
|
||||
router.delete('/posts/:id', authenticateToken, async (req, res) => {
|
||||
router.delete('/posts/:id', authenticateToken, async (req, res, next) => {
|
||||
try {
|
||||
const post = await ForumPost.findByPk(req.params.id);
|
||||
|
||||
@@ -586,12 +586,12 @@ router.delete('/posts/:id', authenticateToken, async (req, res) => {
|
||||
postId: req.params.id,
|
||||
authorId: req.user.id
|
||||
});
|
||||
res.status(500).json({ error: error.message });
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
// PATCH /api/forum/posts/:id/status - Update post status
|
||||
router.patch('/posts/:id/status', authenticateToken, async (req, res) => {
|
||||
router.patch('/posts/:id/status', authenticateToken, async (req, res, next) => {
|
||||
try {
|
||||
const { status } = req.body;
|
||||
const post = await ForumPost.findByPk(req.params.id);
|
||||
@@ -734,12 +734,12 @@ router.patch('/posts/:id/status', authenticateToken, async (req, res) => {
|
||||
postId: req.params.id,
|
||||
authorId: req.user.id
|
||||
});
|
||||
res.status(500).json({ error: error.message });
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
// PATCH /api/forum/posts/:id/accept-answer - Mark/unmark comment as accepted answer
|
||||
router.patch('/posts/:id/accept-answer', authenticateToken, async (req, res) => {
|
||||
router.patch('/posts/:id/accept-answer', authenticateToken, async (req, res, next) => {
|
||||
try {
|
||||
const { commentId } = req.body;
|
||||
const post = await ForumPost.findByPk(req.params.id);
|
||||
@@ -908,12 +908,12 @@ router.patch('/posts/:id/accept-answer', authenticateToken, async (req, res) =>
|
||||
postId: req.params.id,
|
||||
authorId: req.user.id
|
||||
});
|
||||
res.status(500).json({ error: error.message });
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
// POST /api/forum/posts/:id/comments - Add comment/reply
|
||||
router.post('/posts/:id/comments', authenticateToken, uploadForumCommentImages, async (req, res) => {
|
||||
router.post('/posts/:id/comments', authenticateToken, uploadForumCommentImages, async (req, res, next) => {
|
||||
try {
|
||||
const { content, parentCommentId } = req.body;
|
||||
const post = await ForumPost.findByPk(req.params.id);
|
||||
@@ -1073,12 +1073,12 @@ router.post('/posts/:id/comments', authenticateToken, uploadForumCommentImages,
|
||||
postId: req.params.id,
|
||||
authorId: req.user.id
|
||||
});
|
||||
res.status(500).json({ error: error.message });
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
// PUT /api/forum/comments/:id - Edit comment
|
||||
router.put('/comments/:id', authenticateToken, async (req, res) => {
|
||||
router.put('/comments/:id', authenticateToken, async (req, res, next) => {
|
||||
try {
|
||||
const { content } = req.body;
|
||||
const comment = await ForumComment.findByPk(req.params.id);
|
||||
@@ -1122,12 +1122,12 @@ router.put('/comments/:id', authenticateToken, async (req, res) => {
|
||||
commentId: req.params.id,
|
||||
authorId: req.user.id
|
||||
});
|
||||
res.status(500).json({ error: error.message });
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
// DELETE /api/forum/comments/:id - Soft delete comment
|
||||
router.delete('/comments/:id', authenticateToken, async (req, res) => {
|
||||
router.delete('/comments/:id', authenticateToken, async (req, res, next) => {
|
||||
try {
|
||||
const comment = await ForumComment.findByPk(req.params.id);
|
||||
|
||||
@@ -1164,12 +1164,12 @@ router.delete('/comments/:id', authenticateToken, async (req, res) => {
|
||||
commentId: req.params.id,
|
||||
authorId: req.user.id
|
||||
});
|
||||
res.status(500).json({ error: error.message });
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/forum/my-posts - Get user's posts
|
||||
router.get('/my-posts', authenticateToken, async (req, res) => {
|
||||
router.get('/my-posts', authenticateToken, async (req, res, next) => {
|
||||
try {
|
||||
const posts = await ForumPost.findAll({
|
||||
where: { authorId: req.user.id },
|
||||
@@ -1202,12 +1202,12 @@ router.get('/my-posts', authenticateToken, async (req, res) => {
|
||||
stack: error.stack,
|
||||
userId: req.user.id
|
||||
});
|
||||
res.status(500).json({ error: error.message });
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/forum/tags - Get all unique tags for autocomplete
|
||||
router.get('/tags', async (req, res) => {
|
||||
router.get('/tags', async (req, res, next) => {
|
||||
try {
|
||||
const { search } = req.query;
|
||||
|
||||
@@ -1241,14 +1241,14 @@ router.get('/tags', async (req, res) => {
|
||||
stack: error.stack,
|
||||
query: req.query
|
||||
});
|
||||
res.status(500).json({ error: error.message });
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
// ============ ADMIN ROUTES ============
|
||||
|
||||
// DELETE /api/forum/admin/posts/:id - Admin soft-delete post
|
||||
router.delete('/admin/posts/:id', authenticateToken, requireAdmin, async (req, res) => {
|
||||
router.delete('/admin/posts/:id', authenticateToken, requireAdmin, async (req, res, next) => {
|
||||
try {
|
||||
const { reason } = req.body;
|
||||
|
||||
@@ -1321,12 +1321,12 @@ router.delete('/admin/posts/:id', authenticateToken, requireAdmin, async (req, r
|
||||
postId: req.params.id,
|
||||
adminId: req.user.id
|
||||
});
|
||||
res.status(500).json({ error: error.message });
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
// PATCH /api/forum/admin/posts/:id/restore - Admin restore deleted post
|
||||
router.patch('/admin/posts/:id/restore', authenticateToken, requireAdmin, async (req, res) => {
|
||||
router.patch('/admin/posts/:id/restore', authenticateToken, requireAdmin, async (req, res, next) => {
|
||||
try {
|
||||
const post = await ForumPost.findByPk(req.params.id);
|
||||
|
||||
@@ -1362,12 +1362,12 @@ router.patch('/admin/posts/:id/restore', authenticateToken, requireAdmin, async
|
||||
postId: req.params.id,
|
||||
adminId: req.user.id
|
||||
});
|
||||
res.status(500).json({ error: error.message });
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
// DELETE /api/forum/admin/comments/:id - Admin soft-delete comment
|
||||
router.delete('/admin/comments/:id', authenticateToken, requireAdmin, async (req, res) => {
|
||||
router.delete('/admin/comments/:id', authenticateToken, requireAdmin, async (req, res, next) => {
|
||||
try {
|
||||
const { reason } = req.body;
|
||||
|
||||
@@ -1449,12 +1449,12 @@ router.delete('/admin/comments/:id', authenticateToken, requireAdmin, async (req
|
||||
commentId: req.params.id,
|
||||
adminId: req.user.id
|
||||
});
|
||||
res.status(500).json({ error: error.message });
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
// PATCH /api/forum/admin/comments/:id/restore - Admin restore deleted comment
|
||||
router.patch('/admin/comments/:id/restore', authenticateToken, requireAdmin, async (req, res) => {
|
||||
router.patch('/admin/comments/:id/restore', authenticateToken, requireAdmin, async (req, res, next) => {
|
||||
try {
|
||||
const comment = await ForumComment.findByPk(req.params.id);
|
||||
|
||||
@@ -1500,12 +1500,12 @@ router.patch('/admin/comments/:id/restore', authenticateToken, requireAdmin, asy
|
||||
commentId: req.params.id,
|
||||
adminId: req.user.id
|
||||
});
|
||||
res.status(500).json({ error: error.message });
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
// PATCH /api/forum/admin/posts/:id/close - Admin close discussion
|
||||
router.patch('/admin/posts/:id/close', authenticateToken, requireAdmin, async (req, res) => {
|
||||
router.patch('/admin/posts/:id/close', authenticateToken, requireAdmin, async (req, res, next) => {
|
||||
try {
|
||||
const post = await ForumPost.findByPk(req.params.id, {
|
||||
include: [
|
||||
@@ -1615,12 +1615,12 @@ router.patch('/admin/posts/:id/close', authenticateToken, requireAdmin, async (r
|
||||
postId: req.params.id,
|
||||
adminId: req.user.id
|
||||
});
|
||||
res.status(500).json({ error: error.message });
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
// PATCH /api/forum/admin/posts/:id/reopen - Admin reopen discussion
|
||||
router.patch('/admin/posts/:id/reopen', authenticateToken, requireAdmin, async (req, res) => {
|
||||
router.patch('/admin/posts/:id/reopen', authenticateToken, requireAdmin, async (req, res, next) => {
|
||||
try {
|
||||
const post = await ForumPost.findByPk(req.params.id);
|
||||
|
||||
@@ -1655,7 +1655,7 @@ router.patch('/admin/posts/:id/reopen', authenticateToken, requireAdmin, async (
|
||||
postId: req.params.id,
|
||||
adminId: req.user.id
|
||||
});
|
||||
res.status(500).json({ error: error.message });
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user