"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAllCancellationPeriods = getAllCancellationPeriods; exports.getCancellationPeriodById = getCancellationPeriodById; exports.createCancellationPeriod = createCancellationPeriod; exports.updateCancellationPeriod = updateCancellationPeriod; exports.deleteCancellationPeriod = deleteCancellationPeriod; const client_1 = require("@prisma/client"); const prisma = new client_1.PrismaClient(); async function getAllCancellationPeriods(includeInactive = false) { const where = includeInactive ? {} : { isActive: true }; return prisma.cancellationPeriod.findMany({ where, orderBy: { code: 'asc' }, }); } async function getCancellationPeriodById(id) { return prisma.cancellationPeriod.findUnique({ where: { id }, include: { _count: { select: { contracts: true }, }, }, }); } async function createCancellationPeriod(data) { return prisma.cancellationPeriod.create({ data: { ...data, isActive: true, }, }); } async function updateCancellationPeriod(id, data) { return prisma.cancellationPeriod.update({ where: { id }, data, }); } async function deleteCancellationPeriod(id) { // Check if cancellation period is used by any contracts const count = await prisma.contract.count({ where: { cancellationPeriodId: id }, }); if (count > 0) { throw new Error(`Kündigungsfrist kann nicht gelöscht werden, da sie von ${count} Verträgen verwendet wird`); } return prisma.cancellationPeriod.delete({ where: { id } }); } //# sourceMappingURL=cancellation-period.service.js.map