complete new audit system
This commit is contained in:
+10
-8
@@ -1,21 +1,23 @@
|
||||
"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 client_1 = require("@prisma/client");
|
||||
const prisma = new client_1.PrismaClient();
|
||||
const prisma_js_1 = __importDefault(require("../lib/prisma.js"));
|
||||
async function getAllPlatforms(includeInactive = false) {
|
||||
const where = includeInactive ? {} : { isActive: true };
|
||||
return prisma.salesPlatform.findMany({
|
||||
return prisma_js_1.default.salesPlatform.findMany({
|
||||
where,
|
||||
orderBy: { name: 'asc' },
|
||||
});
|
||||
}
|
||||
async function getPlatformById(id) {
|
||||
return prisma.salesPlatform.findUnique({
|
||||
return prisma_js_1.default.salesPlatform.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
_count: {
|
||||
@@ -25,7 +27,7 @@ async function getPlatformById(id) {
|
||||
});
|
||||
}
|
||||
async function createPlatform(data) {
|
||||
return prisma.salesPlatform.create({
|
||||
return prisma_js_1.default.salesPlatform.create({
|
||||
data: {
|
||||
...data,
|
||||
isActive: true,
|
||||
@@ -33,19 +35,19 @@ async function createPlatform(data) {
|
||||
});
|
||||
}
|
||||
async function updatePlatform(id, data) {
|
||||
return prisma.salesPlatform.update({
|
||||
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.contract.count({
|
||||
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.salesPlatform.delete({ where: { id } });
|
||||
return prisma_js_1.default.salesPlatform.delete({ where: { id } });
|
||||
}
|
||||
//# sourceMappingURL=platform.service.js.map
|
||||
Reference in New Issue
Block a user