added place to telecommunication, added contract documents, added invoice to other contracts
This commit is contained in:
+91
@@ -49,6 +49,9 @@ exports.getSipCredentials = getSipCredentials;
|
||||
exports.getCockpit = getCockpit;
|
||||
exports.addSuccessorMeter = addSuccessorMeter;
|
||||
exports.removeContractMeter = removeContractMeter;
|
||||
exports.getContractDocuments = getContractDocuments;
|
||||
exports.uploadContractDocument = uploadContractDocument;
|
||||
exports.deleteContractDocument = deleteContractDocument;
|
||||
exports.snoozeContract = snoozeContract;
|
||||
const prisma_js_1 = __importDefault(require("../lib/prisma.js"));
|
||||
const contractService = __importStar(require("../services/contract.service.js"));
|
||||
@@ -423,6 +426,94 @@ async function removeContractMeter(req, res) {
|
||||
});
|
||||
}
|
||||
}
|
||||
// ==================== VERTRAGSDOKUMENTE ====================
|
||||
async function getContractDocuments(req, res) {
|
||||
try {
|
||||
const contractId = parseInt(req.params.id);
|
||||
const documents = await prisma_js_1.default.contractDocument.findMany({
|
||||
where: { contractId },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
});
|
||||
res.json({ success: true, data: documents });
|
||||
}
|
||||
catch (error) {
|
||||
res.status(500).json({ success: false, error: 'Fehler beim Laden der Dokumente' });
|
||||
}
|
||||
}
|
||||
async function uploadContractDocument(req, res) {
|
||||
try {
|
||||
const contractId = parseInt(req.params.id);
|
||||
const { documentType, notes } = req.body;
|
||||
if (!req.file) {
|
||||
res.status(400).json({ success: false, error: 'Keine Datei hochgeladen' });
|
||||
return;
|
||||
}
|
||||
if (!documentType) {
|
||||
res.status(400).json({ success: false, error: 'Dokumenttyp erforderlich' });
|
||||
return;
|
||||
}
|
||||
const documentPath = `/uploads/contract-documents/${req.file.filename}`;
|
||||
const doc = await prisma_js_1.default.contractDocument.create({
|
||||
data: {
|
||||
contractId,
|
||||
documentType,
|
||||
documentPath,
|
||||
originalName: req.file.originalname,
|
||||
notes: notes || null,
|
||||
uploadedBy: req.user?.email,
|
||||
},
|
||||
});
|
||||
const contract = await prisma_js_1.default.contract.findUnique({ where: { id: contractId }, select: { contractNumber: true, customerId: true } });
|
||||
await (0, audit_service_js_1.logChange)({
|
||||
req, action: 'CREATE', resourceType: 'ContractDocument',
|
||||
resourceId: doc.id.toString(),
|
||||
label: `Dokument "${documentType}" hochgeladen für Vertrag ${contract?.contractNumber}`,
|
||||
details: { typ: documentType, datei: req.file.originalname },
|
||||
customerId: contract?.customerId,
|
||||
});
|
||||
res.status(201).json({ success: true, data: doc });
|
||||
}
|
||||
catch (error) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Fehler beim Hochladen',
|
||||
});
|
||||
}
|
||||
}
|
||||
async function deleteContractDocument(req, res) {
|
||||
try {
|
||||
const documentId = parseInt(req.params.documentId);
|
||||
const contractId = parseInt(req.params.id);
|
||||
const doc = await prisma_js_1.default.contractDocument.findUnique({ where: { id: documentId } });
|
||||
if (!doc || doc.contractId !== contractId) {
|
||||
res.status(404).json({ success: false, error: 'Dokument nicht gefunden' });
|
||||
return;
|
||||
}
|
||||
// Datei löschen
|
||||
const fs = await import('fs');
|
||||
const path = await import('path');
|
||||
const filePath = path.join(process.cwd(), doc.documentPath);
|
||||
if (fs.existsSync(filePath)) {
|
||||
fs.unlinkSync(filePath);
|
||||
}
|
||||
await prisma_js_1.default.contractDocument.delete({ where: { id: documentId } });
|
||||
const contract = await prisma_js_1.default.contract.findUnique({ where: { id: contractId }, select: { contractNumber: true, customerId: true } });
|
||||
await (0, audit_service_js_1.logChange)({
|
||||
req, action: 'DELETE', resourceType: 'ContractDocument',
|
||||
resourceId: documentId.toString(),
|
||||
label: `Dokument "${doc.documentType}" gelöscht von Vertrag ${contract?.contractNumber}`,
|
||||
details: { typ: doc.documentType, datei: doc.originalName },
|
||||
customerId: contract?.customerId,
|
||||
});
|
||||
res.json({ success: true, message: 'Dokument gelöscht' });
|
||||
}
|
||||
catch (error) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Fehler beim Löschen',
|
||||
});
|
||||
}
|
||||
}
|
||||
// ==================== SNOOZE (VERTRAG ZURÜCKSTELLEN) ====================
|
||||
async function snoozeContract(req, res) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user