"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAllPlatforms = getAllPlatforms; exports.getPlatformById = getPlatformById; exports.createPlatform = createPlatform; exports.updatePlatform = updatePlatform; exports.deletePlatform = deletePlatform; const client_1 = require("@prisma/client"); const prisma = new client_1.PrismaClient(); async function getAllPlatforms(includeInactive = false) { const where = includeInactive ? {} : { isActive: true }; return prisma.salesPlatform.findMany({ where, orderBy: { name: 'asc' }, }); } async function getPlatformById(id) { return prisma.salesPlatform.findUnique({ where: { id }, include: { _count: { select: { contracts: true }, }, }, }); } async function createPlatform(data) { return prisma.salesPlatform.create({ data: { ...data, isActive: true, }, }); } async function updatePlatform(id, data) { return prisma.salesPlatform.update({ where: { id }, data, }); } async function deletePlatform(id) { // Check if platform is used by any contracts const count = await prisma.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.salesPlatform.delete({ where: { id } }); } //# sourceMappingURL=platform.service.js.map