complete new audit system
This commit is contained in:
+10
-8
@@ -1,18 +1,20 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getTariffsByProvider = getTariffsByProvider;
|
||||
exports.getTariffById = getTariffById;
|
||||
exports.createTariff = createTariff;
|
||||
exports.updateTariff = updateTariff;
|
||||
exports.deleteTariff = deleteTariff;
|
||||
const client_1 = require("@prisma/client");
|
||||
const prisma = new client_1.PrismaClient();
|
||||
const prisma_js_1 = __importDefault(require("../lib/prisma.js"));
|
||||
async function getTariffsByProvider(providerId, includeInactive = false) {
|
||||
const where = { providerId };
|
||||
if (!includeInactive) {
|
||||
where.isActive = true;
|
||||
}
|
||||
return prisma.tariff.findMany({
|
||||
return prisma_js_1.default.tariff.findMany({
|
||||
where,
|
||||
orderBy: { name: 'asc' },
|
||||
include: {
|
||||
@@ -23,7 +25,7 @@ async function getTariffsByProvider(providerId, includeInactive = false) {
|
||||
});
|
||||
}
|
||||
async function getTariffById(id) {
|
||||
return prisma.tariff.findUnique({
|
||||
return prisma_js_1.default.tariff.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
provider: true,
|
||||
@@ -34,7 +36,7 @@ async function getTariffById(id) {
|
||||
});
|
||||
}
|
||||
async function createTariff(data) {
|
||||
return prisma.tariff.create({
|
||||
return prisma_js_1.default.tariff.create({
|
||||
data: {
|
||||
...data,
|
||||
isActive: true,
|
||||
@@ -42,19 +44,19 @@ async function createTariff(data) {
|
||||
});
|
||||
}
|
||||
async function updateTariff(id, data) {
|
||||
return prisma.tariff.update({
|
||||
return prisma_js_1.default.tariff.update({
|
||||
where: { id },
|
||||
data,
|
||||
});
|
||||
}
|
||||
async function deleteTariff(id) {
|
||||
// Check if tariff is used by any contracts
|
||||
const count = await prisma.contract.count({
|
||||
const count = await prisma_js_1.default.contract.count({
|
||||
where: { tariffId: id },
|
||||
});
|
||||
if (count > 0) {
|
||||
throw new Error(`Tarif kann nicht gelöscht werden, da er von ${count} Verträgen verwendet wird`);
|
||||
}
|
||||
return prisma.tariff.delete({ where: { id } });
|
||||
return prisma_js_1.default.tariff.delete({ where: { id } });
|
||||
}
|
||||
//# sourceMappingURL=tariff.service.js.map
|
||||
Reference in New Issue
Block a user