-
Notifications
You must be signed in to change notification settings - Fork 11
Feat: added database level auditing #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds database-level auditing functionality to track changes made to the User, Submission, and Question models. The implementation uses the @sliit-foss/mongoose-audit plugin with express-http-context to capture the user making each change.
- Added audit plugin integration to User, Submission, and Question schemas
- Modified repository methods to ensure audit hooks are triggered properly
- Set up context middleware to track the authenticated user for audit logging
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/helpers/audit.js | Created audit helper that configures the mongoose-audit plugin with user context retrieval |
| src/models/user.js | Added audit plugin to User schema |
| src/models/submission.js | Added audit plugin to Submission schema |
| src/models/question.js | Added audit plugin to Question schema |
| src/middleware/auth.js | Set authenticated user in express-http-context for audit tracking |
| src/repository/submission.js | Changed from Submission.create() to new Submission().save() to trigger audit hooks |
| src/repository/question/index.js | Changed from Question.deleteOne() to Question.findOneAndDelete() for audit trail |
| src/constants/index.js | Added ctxUser constant for context key |
| src/app.js | Removed unused pick import from lodash |
| package.json | Added @sliit-foss/mongoose-audit dependency and packageManager field |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| export const deleteAQuestion = (filters) => { | ||
| return Question.deleteOne(filters); | ||
| return Question.findOneAndDelete(filters); |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The findOneAndDelete method should have a .lean() call for consistency with other query methods in this file, or it should return the deleted document if needed for audit purposes. Currently, this returns a Mongoose document while other methods return plain JavaScript objects.
| return Question.findOneAndDelete(filters); | |
| return Question.findOneAndDelete(filters).lean(); |
No description provided.