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.getAllCancellationPeriods = getAllCancellationPeriods;
|
||||
exports.getCancellationPeriodById = getCancellationPeriodById;
|
||||
exports.createCancellationPeriod = createCancellationPeriod;
|
||||
exports.updateCancellationPeriod = updateCancellationPeriod;
|
||||
exports.deleteCancellationPeriod = deleteCancellationPeriod;
|
||||
const client_1 = require("@prisma/client");
|
||||
const prisma = new client_1.PrismaClient();
|
||||
const prisma_js_1 = __importDefault(require("../lib/prisma.js"));
|
||||
async function getAllCancellationPeriods(includeInactive = false) {
|
||||
const where = includeInactive ? {} : { isActive: true };
|
||||
return prisma.cancellationPeriod.findMany({
|
||||
return prisma_js_1.default.cancellationPeriod.findMany({
|
||||
where,
|
||||
orderBy: { code: 'asc' },
|
||||
});
|
||||
}
|
||||
async function getCancellationPeriodById(id) {
|
||||
return prisma.cancellationPeriod.findUnique({
|
||||
return prisma_js_1.default.cancellationPeriod.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
_count: {
|
||||
@@ -25,7 +27,7 @@ async function getCancellationPeriodById(id) {
|
||||
});
|
||||
}
|
||||
async function createCancellationPeriod(data) {
|
||||
return prisma.cancellationPeriod.create({
|
||||
return prisma_js_1.default.cancellationPeriod.create({
|
||||
data: {
|
||||
...data,
|
||||
isActive: true,
|
||||
@@ -33,19 +35,19 @@ async function createCancellationPeriod(data) {
|
||||
});
|
||||
}
|
||||
async function updateCancellationPeriod(id, data) {
|
||||
return prisma.cancellationPeriod.update({
|
||||
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.contract.count({
|
||||
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.cancellationPeriod.delete({ where: { id } });
|
||||
return prisma_js_1.default.cancellationPeriod.delete({ where: { id } });
|
||||
}
|
||||
//# sourceMappingURL=cancellation-period.service.js.map
|
||||
Reference in New Issue
Block a user