Feat/audit#658
Merged
Merged
Conversation
|
@nafiuishaaq Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Here is a summary of the implementations I've completed based on your requests:
I have implemented a daily pruning service for audit logs to enhance performance and manage data retention.
closes #620
Pruning Service: A new AuditPruningService was created at src/audit/audit-pruning.service.ts. This service contains the logic to handle the pruning of TransactionHistory and LoginHistory records.
Retention and Archiving: The service is configured to prune records older than 365 days. Before deletion, it archives the old logs into a JSON file within an archives directory.
Scheduled Execution: The pruning process is scheduled to run automatically every day using a cron job.
Integration: The new service has been integrated into the application via a new AuditModule (src/audit/audit.module.ts), which is now imported into the main app.module.ts.
2. Default User Role Seeding
I've adjusted the database seeding process to ensure new users are correctly assigned the default USER role.
closes #623
Schema Update: The role enum field was removed from the User model in prisma/schema.prisma. The system now exclusively uses the roleId relationship to associate users with their roles, making the link more robust.
Seed Script Update: The seeding script at prisma/seed.ts was modified to create users by assigning the appropriate roleId, removing the direct assignment of the role enum.
3. Database Constraint for Transaction Status
To ensure data integrity at the database level, I added a constraint for transaction statuses.
closes #622
Migration: I created a new database migration (prisma/migrations/20260625000000_add_transaction_status_constraint/migration.sql).
Check Constraint: This migration adds a CHECK constraint to the transactions table. This forces the status column to only accept one of the predefined valid values: 'PENDING', 'COMPLETED', or 'CANCELLED'.
4. Tracking for Export and Backup Jobs
I've added a new database table to track the metadata of export and backup jobs.
closes #621
Schema Extension: I updated the prisma/schema.prisma file to include a new ExportJob model. This model will store job metadata, including its type (export or backup), status (pending, running, completed, failed), file reference, and timestamps.
New Enums: I also added JobStatus and JobType enums to support the new model.
Database Migration: A new migration file (prisma/migrations/20260625000001_add_export_jobs/migration.sql) was created to apply these changes, adding the export_jobs table to the database.