feat: Add comprehensive audit logging system
- Add audit logging for contacts (link company, create company from contact) - Add audit logging for notes (create, update, delete) - Add audit logging for companies (update, user assign/remove, reminder CRUD) - Add audit logging for projects (update, user assign/remove) - Add audit logging for todos (update, uncomplete) - Add audit logging for time entries (update, delete) - Add audit logging for timesheets (upload, delete) - Add audit logging for user deletion - Add pagination and filters to audit logs API (userId, action, resource, dateFrom, dateTo) - Add endpoints for distinct actions and resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import * as noteService from '../services/note.service.js';
|
||||
import { logNoteCreated, logNoteUpdated, logNoteDeleted } from '../services/audit.service.js';
|
||||
|
||||
/**
|
||||
* Get all notes
|
||||
@@ -59,6 +60,9 @@ export const createNote = async (req, res, next) => {
|
||||
|
||||
const note = await noteService.createNote(userId, data);
|
||||
|
||||
// Log audit event
|
||||
await logNoteCreated(userId, note.id, note.content, req.ip, req.headers['user-agent']);
|
||||
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
data: note,
|
||||
@@ -76,11 +80,18 @@ export const createNote = async (req, res, next) => {
|
||||
*/
|
||||
export const updateNote = async (req, res, next) => {
|
||||
try {
|
||||
const userId = req.userId;
|
||||
const { noteId } = req.params;
|
||||
const data = req.body;
|
||||
|
||||
// Get old note for audit
|
||||
const oldNote = await noteService.getNoteById(noteId);
|
||||
|
||||
const note = await noteService.updateNote(noteId, data);
|
||||
|
||||
// Log audit event
|
||||
await logNoteUpdated(userId, noteId, oldNote.content, note.content, req.ip, req.headers['user-agent']);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: note,
|
||||
@@ -97,10 +108,17 @@ export const updateNote = async (req, res, next) => {
|
||||
*/
|
||||
export const deleteNote = async (req, res, next) => {
|
||||
try {
|
||||
const userId = req.userId;
|
||||
const { noteId } = req.params;
|
||||
|
||||
// Get note for audit before deletion
|
||||
const note = await noteService.getNoteById(noteId);
|
||||
|
||||
const result = await noteService.deleteNote(noteId);
|
||||
|
||||
// Log audit event
|
||||
await logNoteDeleted(userId, noteId, note.content, req.ip, req.headers['user-agent']);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: result.message,
|
||||
|
||||
Reference in New Issue
Block a user