added contract history
This commit is contained in:
+17
-1
@@ -48,6 +48,7 @@ exports.snoozeContract = snoozeContract;
|
||||
const client_1 = require("@prisma/client");
|
||||
const contractService = __importStar(require("../services/contract.service.js"));
|
||||
const contractCockpitService = __importStar(require("../services/contractCockpit.service.js"));
|
||||
const contractHistoryService = __importStar(require("../services/contractHistory.service.js"));
|
||||
const prisma = new client_1.PrismaClient();
|
||||
async function getContracts(req, res) {
|
||||
try {
|
||||
@@ -154,7 +155,22 @@ async function deleteContract(req, res) {
|
||||
}
|
||||
async function createFollowUp(req, res) {
|
||||
try {
|
||||
const contract = await contractService.createFollowUpContract(parseInt(req.params.id));
|
||||
const previousContractId = parseInt(req.params.id);
|
||||
// Vorgängervertrag laden für Vertragsnummer
|
||||
const previousContract = await prisma.contract.findUnique({
|
||||
where: { id: previousContractId },
|
||||
select: { contractNumber: true },
|
||||
});
|
||||
if (!previousContract) {
|
||||
res.status(404).json({ success: false, error: 'Vorgängervertrag nicht gefunden' });
|
||||
return;
|
||||
}
|
||||
const contract = await contractService.createFollowUpContract(previousContractId);
|
||||
const createdBy = req.user?.email || 'unbekannt';
|
||||
// Historie-Eintrag für den Vorgängervertrag erstellen
|
||||
await contractHistoryService.createFollowUpHistoryEntry(previousContractId, contract.contractNumber, createdBy);
|
||||
// Historie-Eintrag für den neuen Folgevertrag erstellen
|
||||
await contractHistoryService.createNewContractFromPredecessorEntry(contract.id, previousContract.contractNumber, createdBy);
|
||||
res.status(201).json({ success: true, data: contract });
|
||||
}
|
||||
catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user