Add audit logging for CRUD operations

- Extend audit.service.js with logging functions for projects, todos, companies, time tracking, and auth
- Create audit.controller.js for fetching recent audit logs with user info
- Create audit.routes.js with GET /api/audit-logs endpoint
- Add audit logging to project, todo, company, time-tracking, and auth controllers
- Log create/delete operations for projects, todos, companies
- Log timer start/stop for time tracking
- Log login/logout events

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
richardtekula
2025-12-04 10:33:04 +01:00
parent fa7129a5b4
commit a49bff56da
9 changed files with 251 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ import * as companyService from '../services/company.service.js';
import * as noteService from '../services/note.service.js';
import * as companyReminderService from '../services/company-reminder.service.js';
import * as companyEmailService from '../services/company-email.service.js';
import { logCompanyCreated, logCompanyDeleted } from '../services/audit.service.js';
/**
* Get all companies
@@ -114,6 +115,9 @@ export const createCompany = async (req, res, next) => {
const company = await companyService.createCompany(userId, data);
// Log audit event
await logCompanyCreated(userId, company.id, company.name, req.ip, req.headers['user-agent']);
res.status(201).json({
success: true,
data: company,
@@ -153,9 +157,17 @@ export const updateCompany = async (req, res, next) => {
export const deleteCompany = async (req, res, next) => {
try {
const { companyId } = req.params;
const userId = req.userId;
// Get company info before deleting
const company = await companyService.getCompanyById(companyId);
const companyName = company?.name;
const result = await companyService.deleteCompany(companyId);
// Log audit event
await logCompanyDeleted(userId, companyId, companyName, req.ip, req.headers['user-agent']);
res.status(200).json({
success: true,
message: result.message,