Ag Grid anpassungen

This commit is contained in:
Bastian Wagner
2026-02-19 12:21:30 +01:00
parent d7cfc89ba5
commit ef45e91141
31 changed files with 469 additions and 75 deletions

View File

@@ -34,6 +34,9 @@ export class EmailLog {
@Column({type: 'boolean'})
success: boolean;
@Column({type: 'text', default: null})
context: boolean;
@AfterLoad()
setType() {
this.eventName = EmailEvent[this.type]

View File

@@ -20,6 +20,9 @@ export class UserSettings {
@Column({ name: 'send_system_update_notification', default: true, type: 'boolean'})
sendSystemUpdateMails: boolean;
@Column({ name: 'ui_scale', default: 'm' })
uiScale: 's' | 'm' | 'l';
}

View File

@@ -5,10 +5,11 @@ import { DatabaseModule } from 'src/shared/database/database.module';
import { AuthModule } from '../auth/auth.module';
import { SharedServiceModule } from 'src/shared/service/shared.service.module';
import { ConfigService } from '@nestjs/config';
import { MailModule } from '../mail/mail.module';
@Module({
controllers: [KeyController],
providers: [KeyService, ConfigService],
imports: [DatabaseModule, AuthModule, SharedServiceModule],
imports: [DatabaseModule, AuthModule, SharedServiceModule, MailModule],
})
export class KeyModule {}

View File

@@ -11,6 +11,7 @@ import { HelperService } from 'src/shared/service/system.helper.service';
import { FindOperator, IsNull, Not } from 'typeorm';
import { faker } from '@faker-js/faker';
import { ConfigService } from '@nestjs/config';
import { MailService } from '../mail/mail.service';
@Injectable()
export class KeyService {
@@ -20,7 +21,8 @@ export class KeyService {
private readonly handoverRepo: KeyHandoutRepository,
private readonly activityService: ActivityHelperService,
private readonly helper: HelperService,
private readonly configService: ConfigService
private readonly configService: ConfigService,
private readonly mailService: MailService,
) {}
get isDevelopMode(): boolean {
@@ -109,6 +111,21 @@ export class KeyService {
);
this.activityService.logKeyHandover(user, key, key.cylinder[0].system, res);
try {
if (key && key.cylinder && key.cylinder[0].system) {
const managerOb: Key = await this.keyrepository.findOne({
where: { id: keyID },
relations: [ 'cylinder', 'cylinder.system', 'cylinder.system.managers', 'cylinder.system.managers.settings' ]
});
console.log(managerOb.cylinder[0].system.managers)
managerOb.cylinder[0].system.managers.filter(m => m.settings.sendSystemUpdateMails).forEach(m => {
this.mailService.sendKeyHandoutMail({ to: m, key, handoutAction: res })
})
}
} catch (e){
console.log(e)
}
return res;
}

View File

@@ -19,11 +19,12 @@ export class LogService {
private async logEmail(data: EmailLogDto) {
const log = this.emailLogRepo.create(data);
console.log(log)
const logEntry = await this.emailLogRepo.save(log);
}
private async logAuthEvent(data: User) {
console.error("auth logging not implemented")
// console.error("auth logging not implemented")
}
}
@@ -34,7 +35,8 @@ export enum LogType {
export enum EmailEvent {
GrantSystemAccess,
RemoveSystemAccess
RemoveSystemAccess,
KeyHandout
}
export interface EmailLogDto {

View File

@@ -3,7 +3,7 @@ import { Injectable } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { EmailEvent, LogService, LogType } from "../log/log.service";
import { KeySystem } from "src/model/entitites/system.entity";
import { User } from "src/model/entitites";
import { Key, KeyHandout, User } from "src/model/entitites";
@Injectable()
export class MailService {
@@ -14,6 +14,46 @@ export class MailService {
) {
}
async sendKeyHandoutMail({to, key, handoutAction}: {to: User, key: Key, handoutAction: KeyHandout}) {
const keyAction = handoutAction.direction == 'out' ? 'wurde ausgegeben' : 'wurde zurückgegeben';
const keyExtendedAction = handoutAction.direction == 'return' ? `wurde von ${handoutAction.customer.name} zurückgegeben` : `wurde an ${handoutAction.customer.name} ausgegeben`;
const subject = handoutAction.direction == 'out' ? 'Schlüssel ausgegeben' : 'Schlüssel zurückgegeben';
const context = {
keyAction,
keyExtendedAction,
firstName: to.firstName,
keyNr: key.nr,
keyName: key.name,
url: 'https://keyvaultpro.de/keys?nr=' + key.nr
}
this.mailserService.sendMail({
template: './key-handout-changed',
to: to.username,
from: this.configService.get<string>('MAILER_FROM'),
subject: subject,
context
}).then(v => {
this.logService.log(LogType.Mail, {
to: to.username,
success: true,
message: v.response,
type: EmailEvent.KeyHandout,
system: key.cylinder[0].system,
context: JSON.stringify(handoutAction)
})
}).catch(e => {
this.logService.log(LogType.Mail, {
to,
success: false,
message: e.response,
type: EmailEvent.KeyHandout,
system: key.cylinder[0].system,
context: JSON.stringify(handoutAction)
})
})
}
async sendAccessGrantedMail({to, system}: {to: User, system: KeySystem}) {
this.mailserService.sendMail({
template: './access',

View File

@@ -0,0 +1,94 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Zugriff gewährt</title>
<style>
/* General styles */
body {
font-family: 'Roboto', Arial, sans-serif;
background-color: #f5f5f5;
color: #424242;
margin: 0;
padding: 0;
}
.container {
max-width: 600px;
margin: 20px auto;
background: #ffffff;
border-radius: 12px;
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
overflow: hidden;
}
.header {
background-color: #2196f3; /* Freundliches Blau */
color: #ffffff;
padding: 20px;
text-align: center;
}
.header h1 {
margin: 0;
font-size: 1.5rem;
}
.content {
padding: 24px 20px;
line-height: 1.6;
color: #424242;
}
.content p {
margin: 0 0 16px;
}
.button-container {
text-align: center;
margin: 24px 0;
}
.btn {
display: inline-block;
padding: 12px 24px;
font-size: 16px;
color: #ffffff;
background-color: #2196f3; /* Gleicher Blauton */
text-decoration: none;
border-radius: 24px;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
transition: background-color 0.3s ease, box-shadow 0.3s ease;
}
.btn:hover {
background-color: #1769aa; /* Dunkleres Blau für Hover */
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.3);
}
.footer {
background-color: #f5f5f5;
text-align: center;
padding: 16px;
font-size: 0.875rem;
color: #757575;
}
.footer a {
color: #2196f3;
text-decoration: none;
}
.footer a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>Schlüssel {{ keyAction }}</h1>
</div>
<div class="content">
<p>Hallo {{firstName}},</p>
<p>der Schlüssel {{ keyName }} ({{ keyNr }}) wurde {{ keyExtendedAction }}</p>
<div class="button-container">
<a href="{{ url }}" class="btn">Website aufrufen</a>
</div>
</div>
<div class="footer">
</div>
</div>
</body>
</html>