Discussion-and-Mod-Requests #199

Open
Ajdj100 wants to merge 5 commits from DIscussion-and-Mod-Requests into main
3 changed files with 8 additions and 4 deletions
Showing only changes of commit e8b30f6947 - Show all commits

View File

@@ -17,10 +17,12 @@ router.post('/comment', async (req: Request, res: Response) => {
try {
let comment = req.body as DiscussionComment;
console.log(comment);
if (!comment.content || comment.content.trim() === '') {
return res.status(400).json({ error: 'Comment content cannot be empty' });
}
await postComment(comment, req.user.id);
let rowID = await postComment(comment, req.user.id);
audit.discussion('comment_posted', { actorId: req.user.id, targetId: rowID }, { parent: comment.post_id })
res.sendStatus(201);
} catch (error) {
logger.error('app', "Failed to post comments", error);

View File

@@ -145,4 +145,6 @@ export async function postComment(commentData: DiscussionComment, poster: number
if (!result.affectedRows || result.affectedRows !== 1) {
throw new Error('Failed to insert comment: expected 1 row to be inserted');
}
return Number(result.insertId);
}

View File

@@ -57,7 +57,7 @@ class AuditLogger {
return this.record('course', action, context, data);
}
discussion(action: 'created', context: AuditContext, data: any = {}) {
discussion(action: 'created' | 'comment_posted', context: AuditContext, data: any = {}) {
return this.record('discussion', action, context, data);
}
}