Handled audit log and some other edge cases
All checks were successful
Pull Request CI / Merge Check (pull_request) Successful in 5m18s
All checks were successful
Pull Request CI / Merge Check (pull_request) Successful in 5m18s
This commit is contained in:
@@ -17,10 +17,12 @@ router.post('/comment', async (req: Request, res: Response) => {
|
|||||||
try {
|
try {
|
||||||
let comment = req.body as DiscussionComment;
|
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);
|
res.sendStatus(201);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('app', "Failed to post comments", error);
|
logger.error('app', "Failed to post comments", error);
|
||||||
|
|||||||
@@ -145,4 +145,6 @@ export async function postComment(commentData: DiscussionComment, poster: number
|
|||||||
if (!result.affectedRows || result.affectedRows !== 1) {
|
if (!result.affectedRows || result.affectedRows !== 1) {
|
||||||
throw new Error('Failed to insert comment: expected 1 row to be inserted');
|
throw new Error('Failed to insert comment: expected 1 row to be inserted');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Number(result.insertId);
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,7 @@ class AuditLogger {
|
|||||||
return this.record('course', action, context, data);
|
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);
|
return this.record('discussion', action, context, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user