complete new audit system

This commit is contained in:
2026-03-21 18:23:54 +01:00
parent 38b3b7da73
commit fd55742c57
159 changed files with 2841 additions and 736 deletions
+9 -10
View File
@@ -10,14 +10,13 @@ exports.getCustomerPortalPassword = getCustomerPortalPassword;
exports.createUser = createUser;
exports.getUserById = getUserById;
exports.getCustomerPortalUser = getCustomerPortalUser;
const client_1 = require("@prisma/client");
const prisma_js_1 = __importDefault(require("../lib/prisma.js"));
const bcryptjs_1 = __importDefault(require("bcryptjs"));
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
const encryption_js_1 = require("../utils/encryption.js");
const prisma = new client_1.PrismaClient();
// Mitarbeiter-Login
async function login(email, password) {
const user = await prisma.user.findUnique({
const user = await prisma_js_1.default.user.findUnique({
where: { email },
include: {
roles: {
@@ -75,7 +74,7 @@ async function login(email, password) {
// Kundenportal-Login
async function customerLogin(email, password) {
console.log('[CustomerLogin] Versuch mit E-Mail:', email);
const customer = await prisma.customer.findUnique({
const customer = await prisma_js_1.default.customer.findUnique({
where: { portalEmail: email },
include: {
// Kunden, die dieser Kunde vertreten kann
@@ -107,7 +106,7 @@ async function customerLogin(email, password) {
throw new Error('Ungültige Anmeldedaten');
}
// Letzte Anmeldung aktualisieren
await prisma.customer.update({
await prisma_js_1.default.customer.update({
where: { id: customer.id },
data: { portalLastLogin: new Date() },
});
@@ -155,7 +154,7 @@ async function setCustomerPortalPassword(customerId, password) {
const hashedPassword = await bcryptjs_1.default.hash(password, 10);
const encryptedPassword = (0, encryption_js_1.encrypt)(password);
console.log('[SetPortalPassword] Hash erstellt, Länge:', hashedPassword.length);
await prisma.customer.update({
await prisma_js_1.default.customer.update({
where: { id: customerId },
data: {
portalPasswordHash: hashedPassword,
@@ -166,7 +165,7 @@ async function setCustomerPortalPassword(customerId, password) {
}
// Kundenportal-Passwort im Klartext abrufen
async function getCustomerPortalPassword(customerId) {
const customer = await prisma.customer.findUnique({
const customer = await prisma_js_1.default.customer.findUnique({
where: { id: customerId },
select: { portalPasswordEncrypted: true },
});
@@ -183,7 +182,7 @@ async function getCustomerPortalPassword(customerId) {
}
async function createUser(data) {
const hashedPassword = await bcryptjs_1.default.hash(data.password, 10);
const user = await prisma.user.create({
const user = await prisma_js_1.default.user.create({
data: {
email: data.email,
password: hashedPassword,
@@ -211,7 +210,7 @@ async function createUser(data) {
};
}
async function getUserById(id) {
const user = await prisma.user.findUnique({
const user = await prisma_js_1.default.user.findUnique({
where: { id },
include: {
roles: {
@@ -256,7 +255,7 @@ async function getUserById(id) {
}
// Kundenportal-Benutzer laden (für /me Endpoint)
async function getCustomerPortalUser(customerId) {
const customer = await prisma.customer.findUnique({
const customer = await prisma_js_1.default.customer.findUnique({
where: { id: customerId },
include: {
representingFor: {