"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAllPlatforms = getAllPlatforms; exports.getPlatformById = getPlatformById; exports.createPlatform = createPlatform; exports.updatePlatform = updatePlatform; exports.deletePlatform = deletePlatform; const prisma_js_1 = __importDefault(require("../lib/prisma.js")); async function getAllPlatforms(includeInactive = false) { const where = includeInactive ? {} : { isActive: true }; return prisma_js_1.default.salesPlatform.findMany({ where, orderBy: { name: 'asc' }, }); } async function getPlatformById(id) { return prisma_js_1.default.salesPlatform.findUnique({ where: { id }, include: { _count: { select: { contracts: true }, }, }, }); } async function createPlatform(data) { return prisma_js_1.default.salesPlatform.create({ data: { ...data, isActive: true, }, }); } async function updatePlatform(id, data) { return prisma_js_1.default.salesPlatform.update({ where: { id }, data, }); } async function deletePlatform(id) { // Check if platform is used by any contracts const count = await prisma_js_1.default.contract.count({ where: { salesPlatformId: id }, }); if (count > 0) { throw new Error(`Plattform kann nicht gelöscht werden, da sie von ${count} Verträgen verwendet wird`); } return prisma_js_1.default.salesPlatform.delete({ where: { id } }); } //# sourceMappingURL=platform.service.js.map