"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAllCancellationPeriods = getAllCancellationPeriods; exports.getCancellationPeriodById = getCancellationPeriodById; exports.createCancellationPeriod = createCancellationPeriod; exports.updateCancellationPeriod = updateCancellationPeriod; exports.deleteCancellationPeriod = deleteCancellationPeriod; const prisma_js_1 = __importDefault(require("../lib/prisma.js")); async function getAllCancellationPeriods(includeInactive = false) { const where = includeInactive ? {} : { isActive: true }; return prisma_js_1.default.cancellationPeriod.findMany({ where, orderBy: { code: 'asc' }, }); } async function getCancellationPeriodById(id) { return prisma_js_1.default.cancellationPeriod.findUnique({ where: { id }, include: { _count: { select: { contracts: true }, }, }, }); } async function createCancellationPeriod(data) { return prisma_js_1.default.cancellationPeriod.create({ data: { ...data, isActive: true, }, }); } async function updateCancellationPeriod(id, data) { return prisma_js_1.default.cancellationPeriod.update({ where: { id }, data, }); } async function deleteCancellationPeriod(id) { // Check if cancellation period is used by any contracts const count = await prisma_js_1.default.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_js_1.default.cancellationPeriod.delete({ where: { id } }); } //# sourceMappingURL=cancellation-period.service.js.map