complete new audit system
This commit is contained in:
@@ -3,6 +3,7 @@ import * as contractTaskService from '../services/contractTask.service.js';
|
||||
import * as contractService from '../services/contract.service.js';
|
||||
import * as customerService from '../services/customer.service.js';
|
||||
import * as appSettingService from '../services/appSetting.service.js';
|
||||
import { logChange } from '../services/audit.service.js';
|
||||
import { ApiResponse, AuthRequest } from '../types/index.js';
|
||||
|
||||
// ==================== ALL TASKS (Dashboard & Task List) ====================
|
||||
@@ -147,6 +148,12 @@ export async function createTask(req: AuthRequest, res: Response): Promise<void>
|
||||
createdBy,
|
||||
});
|
||||
|
||||
await logChange({
|
||||
req, action: 'CREATE', resourceType: 'ContractTask',
|
||||
resourceId: task.id.toString(),
|
||||
label: `Aufgabe "${title}" erstellt`,
|
||||
});
|
||||
|
||||
res.status(201).json({ success: true, data: task } as ApiResponse);
|
||||
} catch (error) {
|
||||
res.status(400).json({
|
||||
@@ -212,6 +219,12 @@ export async function createSupportTicket(req: AuthRequest, res: Response): Prom
|
||||
createdBy,
|
||||
});
|
||||
|
||||
await logChange({
|
||||
req, action: 'CREATE', resourceType: 'ContractTask',
|
||||
resourceId: task.id.toString(),
|
||||
label: `Support-Anfrage "${title}" erstellt`,
|
||||
});
|
||||
|
||||
res.status(201).json({ success: true, data: task } as ApiResponse);
|
||||
} catch (error) {
|
||||
res.status(400).json({
|
||||
@@ -232,6 +245,12 @@ export async function updateTask(req: AuthRequest, res: Response): Promise<void>
|
||||
visibleInPortal,
|
||||
});
|
||||
|
||||
await logChange({
|
||||
req, action: 'UPDATE', resourceType: 'ContractTask',
|
||||
resourceId: taskId.toString(),
|
||||
label: `Aufgabe aktualisiert`,
|
||||
});
|
||||
|
||||
res.json({ success: true, data: task } as ApiResponse);
|
||||
} catch (error) {
|
||||
res.status(400).json({
|
||||
@@ -245,6 +264,11 @@ export async function completeTask(req: AuthRequest, res: Response): Promise<voi
|
||||
try {
|
||||
const taskId = parseInt(req.params.taskId);
|
||||
const task = await contractTaskService.completeTask(taskId);
|
||||
await logChange({
|
||||
req, action: 'UPDATE', resourceType: 'ContractTask',
|
||||
resourceId: taskId.toString(),
|
||||
label: `Aufgabe abgeschlossen`,
|
||||
});
|
||||
res.json({ success: true, data: task } as ApiResponse);
|
||||
} catch (error) {
|
||||
res.status(400).json({
|
||||
@@ -258,6 +282,11 @@ export async function reopenTask(req: AuthRequest, res: Response): Promise<void>
|
||||
try {
|
||||
const taskId = parseInt(req.params.taskId);
|
||||
const task = await contractTaskService.reopenTask(taskId);
|
||||
await logChange({
|
||||
req, action: 'UPDATE', resourceType: 'ContractTask',
|
||||
resourceId: taskId.toString(),
|
||||
label: `Aufgabe wiedereröffnet`,
|
||||
});
|
||||
res.json({ success: true, data: task } as ApiResponse);
|
||||
} catch (error) {
|
||||
res.status(400).json({
|
||||
@@ -271,6 +300,11 @@ export async function deleteTask(req: AuthRequest, res: Response): Promise<void>
|
||||
try {
|
||||
const taskId = parseInt(req.params.taskId);
|
||||
await contractTaskService.deleteTask(taskId);
|
||||
await logChange({
|
||||
req, action: 'DELETE', resourceType: 'ContractTask',
|
||||
resourceId: taskId.toString(),
|
||||
label: `Aufgabe gelöscht`,
|
||||
});
|
||||
res.json({ success: true, message: 'Aufgabe gelöscht' } as ApiResponse);
|
||||
} catch (error) {
|
||||
res.status(400).json({
|
||||
@@ -303,6 +337,12 @@ export async function createSubtask(req: AuthRequest, res: Response): Promise<vo
|
||||
createdBy,
|
||||
});
|
||||
|
||||
await logChange({
|
||||
req, action: 'CREATE', resourceType: 'ContractSubtask',
|
||||
resourceId: subtask.id.toString(),
|
||||
label: `Unteraufgabe "${title}" erstellt`,
|
||||
});
|
||||
|
||||
res.status(201).json({ success: true, data: subtask } as ApiResponse);
|
||||
} catch (error) {
|
||||
res.status(400).json({
|
||||
@@ -369,6 +409,12 @@ export async function createCustomerReply(req: AuthRequest, res: Response): Prom
|
||||
createdBy,
|
||||
});
|
||||
|
||||
await logChange({
|
||||
req, action: 'CREATE', resourceType: 'ContractSubtask',
|
||||
resourceId: subtask.id.toString(),
|
||||
label: `Kundenantwort erstellt`,
|
||||
});
|
||||
|
||||
res.status(201).json({ success: true, data: subtask } as ApiResponse);
|
||||
} catch (error) {
|
||||
res.status(400).json({
|
||||
@@ -392,6 +438,11 @@ export async function updateSubtask(req: AuthRequest, res: Response): Promise<vo
|
||||
}
|
||||
|
||||
const subtask = await contractTaskService.updateSubtask(subtaskId, { title });
|
||||
await logChange({
|
||||
req, action: 'UPDATE', resourceType: 'ContractSubtask',
|
||||
resourceId: subtaskId.toString(),
|
||||
label: `Unteraufgabe aktualisiert`,
|
||||
});
|
||||
res.json({ success: true, data: subtask } as ApiResponse);
|
||||
} catch (error) {
|
||||
res.status(400).json({
|
||||
@@ -405,6 +456,11 @@ export async function completeSubtask(req: AuthRequest, res: Response): Promise<
|
||||
try {
|
||||
const subtaskId = parseInt(req.params.subtaskId);
|
||||
const subtask = await contractTaskService.completeSubtask(subtaskId);
|
||||
await logChange({
|
||||
req, action: 'UPDATE', resourceType: 'ContractSubtask',
|
||||
resourceId: subtaskId.toString(),
|
||||
label: `Unteraufgabe abgeschlossen`,
|
||||
});
|
||||
res.json({ success: true, data: subtask } as ApiResponse);
|
||||
} catch (error) {
|
||||
res.status(400).json({
|
||||
@@ -418,6 +474,11 @@ export async function reopenSubtask(req: AuthRequest, res: Response): Promise<vo
|
||||
try {
|
||||
const subtaskId = parseInt(req.params.subtaskId);
|
||||
const subtask = await contractTaskService.reopenSubtask(subtaskId);
|
||||
await logChange({
|
||||
req, action: 'UPDATE', resourceType: 'ContractSubtask',
|
||||
resourceId: subtaskId.toString(),
|
||||
label: `Unteraufgabe wiedereröffnet`,
|
||||
});
|
||||
res.json({ success: true, data: subtask } as ApiResponse);
|
||||
} catch (error) {
|
||||
res.status(400).json({
|
||||
@@ -431,6 +492,11 @@ export async function deleteSubtask(req: AuthRequest, res: Response): Promise<vo
|
||||
try {
|
||||
const subtaskId = parseInt(req.params.subtaskId);
|
||||
await contractTaskService.deleteSubtask(subtaskId);
|
||||
await logChange({
|
||||
req, action: 'DELETE', resourceType: 'ContractSubtask',
|
||||
resourceId: subtaskId.toString(),
|
||||
label: `Unteraufgabe gelöscht`,
|
||||
});
|
||||
res.json({ success: true, message: 'Unteraufgabe gelöscht' } as ApiResponse);
|
||||
} catch (error) {
|
||||
res.status(400).json({
|
||||
|
||||
Reference in New Issue
Block a user