Discussion-and-Mod-Requests #199
@@ -6,7 +6,7 @@ import { requireLogin, requireMemberState, requireRole } from '../middleware/aut
|
||||
import { logger } from '../services/logging/logger';
|
||||
import { audit } from '../services/logging/auditLog';
|
||||
import { MemberState } from '@app/shared/types/member';
|
||||
import { createDiscussion, getAllDiscussions, getDiscussionById, postComment } from '../services/db/discussionService';
|
||||
import { createDiscussion, getAllDiscussions, getDiscussionById, getPostComments, postComment } from '../services/db/discussionService';
|
||||
import { ModRequest } from '@app/shared/schemas/modRequest';
|
||||
import { DiscussionComment } from '@app/shared/types/discussion';
|
||||
|
||||
@@ -23,7 +23,19 @@ router.post('/comment', async (req: Request, res: Response) => {
|
||||
|
||||
res.sendStatus(201);
|
||||
} catch (error) {
|
||||
logger.error('app', "Failed to post comments", error);
|
||||
res.sendStatus(500);
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/:postId/comments', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const postId = parseInt(req.params.postId);
|
||||
const comments = await getPostComments(postId);
|
||||
res.json(comments);
|
||||
} catch (error) {
|
||||
logger.error('app', "Failed to fetch comments", error);
|
||||
res.sendStatus(500);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -20,3 +20,17 @@ export async function postComment(comment: DiscussionComment) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getPostComments(postId: number): Promise<DiscussionComment[]> {
|
||||
const res = await fetch(`${addr}/discussions/${postId}/comments`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
credentials: 'include',
|
||||
});
|
||||
if (!res.ok) {
|
||||
throw new Error("Failed to fetch comments");
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,14 +3,23 @@
|
||||
import { DiscussionComment } from '@shared/types/discussion';
|
||||
import DiscussionCommentView from './DiscussionCommentView.vue';
|
||||
import CommentForm from './CommentForm.vue';
|
||||
import { ref } from 'process';
|
||||
import { getPostComments } from '@/api/discussion';
|
||||
|
||||
const props = defineProps<{
|
||||
parentId: number;
|
||||
comments: DiscussionComment[];
|
||||
}>();
|
||||
parentId: number,
|
||||
comments: DiscussionComment[]
|
||||
}>()
|
||||
|
||||
function onCommentPosted() {
|
||||
// TODO: Refresh comments if needed
|
||||
const emit = defineEmits<{
|
||||
(e: 'commentsUpdated', comments: DiscussionComment[]): void
|
||||
}>()
|
||||
|
||||
async function onCommentPosted() {
|
||||
const res = await getPostComments(props.parentId);
|
||||
console.log(res);
|
||||
// tell parent to update state
|
||||
emit('commentsUpdated', res);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@
|
||||
</div>
|
||||
|
||||
<!-- discussion placeholder -->
|
||||
<CommentThread :parent-id="post.id" :comments="post.comments" />
|
||||
<CommentThread :parent-id="post.id" :comments="post.comments" @comments-updated="post.comments = $event" />
|
||||
|
||||
</div>
|
||||
<div v-else>
|
||||
|
||||
Reference in New Issue
Block a user