complete new audit system
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Request, Response } from 'express';
|
||||
import * as tariffService from '../services/tariff.service.js';
|
||||
import { logChange } from '../services/audit.service.js';
|
||||
import { ApiResponse } from '../types/index.js';
|
||||
|
||||
export async function getTariffs(req: Request, res: Response): Promise<void> {
|
||||
@@ -39,6 +40,11 @@ export async function createTariff(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const providerId = parseInt(req.params.providerId);
|
||||
const tariff = await tariffService.createTariff({ ...req.body, providerId });
|
||||
await logChange({
|
||||
req, action: 'CREATE', resourceType: 'Tariff',
|
||||
resourceId: tariff.id.toString(),
|
||||
label: `Tarif ${tariff.name} angelegt`,
|
||||
});
|
||||
res.status(201).json({ success: true, data: tariff } as ApiResponse);
|
||||
} catch (error) {
|
||||
res.status(400).json({
|
||||
@@ -51,6 +57,11 @@ export async function createTariff(req: Request, res: Response): Promise<void> {
|
||||
export async function updateTariff(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const tariff = await tariffService.updateTariff(parseInt(req.params.id), req.body);
|
||||
await logChange({
|
||||
req, action: 'UPDATE', resourceType: 'Tariff',
|
||||
resourceId: tariff.id.toString(),
|
||||
label: `Tarif ${tariff.name} aktualisiert`,
|
||||
});
|
||||
res.json({ success: true, data: tariff } as ApiResponse);
|
||||
} catch (error) {
|
||||
res.status(400).json({
|
||||
@@ -62,7 +73,14 @@ export async function updateTariff(req: Request, res: Response): Promise<void> {
|
||||
|
||||
export async function deleteTariff(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
await tariffService.deleteTariff(parseInt(req.params.id));
|
||||
const tariffId = parseInt(req.params.id);
|
||||
const tariff = await tariffService.getTariffById(tariffId);
|
||||
await tariffService.deleteTariff(tariffId);
|
||||
await logChange({
|
||||
req, action: 'DELETE', resourceType: 'Tariff',
|
||||
resourceId: tariffId.toString(),
|
||||
label: `Tarif ${tariff?.name || tariffId} gelöscht`,
|
||||
});
|
||||
res.json({ success: true, message: 'Tarif gelöscht' } as ApiResponse);
|
||||
} catch (error) {
|
||||
res.status(400).json({
|
||||
|
||||
Reference in New Issue
Block a user