Auto-Vertragsstatus: Lieferbestätigung hochladen → DRAFT auf ACTIVE
Ergänzung zum Cancellation-Trigger: wenn ein ContractDocument mit documentType "Lieferbestätigung" hochgeladen wird und der Vertrag aktuell DRAFT ist, wird er automatisch auf ACTIVE gesetzt (+ Audit-Log). Greift an beiden Upload-Pfaden: - POST /api/contracts/:id/documents (Direkt-Upload via ContractDetail) - POST /api/emails/:id/attachments/:filename/save-as-contract-document (Email-Anhang als Vertragsdokument speichern) Vergleich case-insensitive + getrimmt auf "lieferbestätigung". Andere Typen (Auftragsformular etc.) lösen keinen Wechsel aus. Nicht-DRAFT- Verträge (ACTIVE/CANCELLED/EXPIRED/DEACTIVATED) bleiben unverändert. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,7 @@ import { decrypt } from '../utils/encryption.js';
|
||||
import { ApiResponse } from '../types/index.js';
|
||||
import { getCustomerTargets, getContractTargets, getIdentityDocumentTargets, getBankCardTargets, documentTargets } from '../config/documentTargets.config.js';
|
||||
import { generateEmailPdf } from '../services/pdfService.js';
|
||||
import { maybeActivateOnDeliveryConfirmation } from '../services/contractStatusScheduler.service.js';
|
||||
import { DocumentType } from '@prisma/client';
|
||||
import prisma from '../lib/prisma.js';
|
||||
import path from 'path';
|
||||
@@ -2001,6 +2002,9 @@ export async function saveAttachmentAsContractDocument(req: Request, res: Respon
|
||||
},
|
||||
});
|
||||
|
||||
// Falls Lieferbestätigung + Vertrag DRAFT → automatisch auf ACTIVE
|
||||
await maybeActivateOnDeliveryConfirmation(contract.id, documentType, req);
|
||||
|
||||
res.json({ success: true, data: doc } as ApiResponse);
|
||||
} catch (error) {
|
||||
console.error('saveAttachmentAsContractDocument error:', error);
|
||||
|
||||
@@ -7,6 +7,7 @@ import * as authorizationService from '../services/authorization.service.js';
|
||||
import { ApiResponse, AuthRequest } from '../types/index.js';
|
||||
import { logChange } from '../services/audit.service.js';
|
||||
import { canAccessContract } from '../utils/accessControl.js';
|
||||
import { maybeActivateOnDeliveryConfirmation } from '../services/contractStatusScheduler.service.js';
|
||||
|
||||
export async function getContracts(req: AuthRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
@@ -494,6 +495,9 @@ export async function uploadContractDocument(req: AuthRequest, res: Response): P
|
||||
customerId: contract?.customerId,
|
||||
});
|
||||
|
||||
// Falls Lieferbestätigung + Vertrag DRAFT → automatisch auf ACTIVE
|
||||
await maybeActivateOnDeliveryConfirmation(contractId, documentType, req);
|
||||
|
||||
res.status(201).json({ success: true, data: doc } as ApiResponse);
|
||||
} catch (error) {
|
||||
res.status(400).json({
|
||||
|
||||
Reference in New Issue
Block a user