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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user