complete new audit system

This commit is contained in:
2026-03-21 18:23:54 +01:00
parent 38b3b7da73
commit fd55742c57
159 changed files with 2841 additions and 736 deletions
@@ -1,5 +1,6 @@
import { Request, Response } from 'express';
import * as cancellationPeriodService from '../services/cancellation-period.service.js';
import { logChange } from '../services/audit.service.js';
import { ApiResponse } from '../types/index.js';
export async function getCancellationPeriods(req: Request, res: Response): Promise<void> {
@@ -37,6 +38,11 @@ export async function getCancellationPeriod(req: Request, res: Response): Promis
export async function createCancellationPeriod(req: Request, res: Response): Promise<void> {
try {
const period = await cancellationPeriodService.createCancellationPeriod(req.body);
await logChange({
req, action: 'CREATE', resourceType: 'CancellationPeriod',
resourceId: period.id.toString(),
label: `Kündigungsfrist ${period.description} angelegt`,
});
res.status(201).json({ success: true, data: period } as ApiResponse);
} catch (error) {
res.status(400).json({
@@ -49,6 +55,11 @@ export async function createCancellationPeriod(req: Request, res: Response): Pro
export async function updateCancellationPeriod(req: Request, res: Response): Promise<void> {
try {
const period = await cancellationPeriodService.updateCancellationPeriod(parseInt(req.params.id), req.body);
await logChange({
req, action: 'UPDATE', resourceType: 'CancellationPeriod',
resourceId: period.id.toString(),
label: `Kündigungsfrist ${period.description} aktualisiert`,
});
res.json({ success: true, data: period } as ApiResponse);
} catch (error) {
res.status(400).json({
@@ -60,7 +71,14 @@ export async function updateCancellationPeriod(req: Request, res: Response): Pro
export async function deleteCancellationPeriod(req: Request, res: Response): Promise<void> {
try {
await cancellationPeriodService.deleteCancellationPeriod(parseInt(req.params.id));
const periodId = parseInt(req.params.id);
const period = await cancellationPeriodService.getCancellationPeriodById(periodId);
await cancellationPeriodService.deleteCancellationPeriod(periodId);
await logChange({
req, action: 'DELETE', resourceType: 'CancellationPeriod',
resourceId: periodId.toString(),
label: `Kündigungsfrist ${period?.description || periodId} gelöscht`,
});
res.json({ success: true, message: 'Kündigungsfrist gelöscht' } as ApiResponse);
} catch (error) {
res.status(400).json({