Logging & Styling
This commit is contained in:
@@ -2,6 +2,8 @@ import { MailerService } from "@nestjs-modules/mailer";
|
||||
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";
|
||||
|
||||
@Injectable()
|
||||
export class MailService {
|
||||
@@ -12,56 +14,60 @@ export class MailService {
|
||||
) {
|
||||
}
|
||||
|
||||
async sendAccessGrantedMail({to, firstName, systemName}: {to: string, firstName: string, systemName: string}) {
|
||||
async sendAccessGrantedMail({to, system}: {to: User, system: KeySystem}) {
|
||||
this.mailserService.sendMail({
|
||||
template: './access',
|
||||
to: to,
|
||||
to: to.username,
|
||||
from: this.configService.get<string>('MAILER_FROM'),
|
||||
subject: 'Zugriff gewährt',
|
||||
context: {
|
||||
firstName,
|
||||
systemName
|
||||
firstName: to.firstName,
|
||||
systemName: system.name
|
||||
}
|
||||
}).then(v => {
|
||||
this.logService.log(LogType.Mail, {
|
||||
to,
|
||||
success: true,
|
||||
message: v.response,
|
||||
type: EmailEvent.GrantSystemAccess
|
||||
type: EmailEvent.GrantSystemAccess,
|
||||
system
|
||||
})
|
||||
}).catch(e => {
|
||||
this.logService.log(LogType.Mail, {
|
||||
to,
|
||||
success: false,
|
||||
message: e.response,
|
||||
type: EmailEvent.GrantSystemAccess
|
||||
type: EmailEvent.GrantSystemAccess,
|
||||
system
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
sendAccessRemovedMail({to, firstName, systemName}: {to: string, firstName: string, systemName: string}) {
|
||||
sendAccessRemovedMail({to, system}: {to: User, system: KeySystem}) {
|
||||
this.mailserService.sendMail({
|
||||
template: './access-removed',
|
||||
to: to,
|
||||
to: to.username,
|
||||
from: this.configService.get<string>('MAILER_FROM'),
|
||||
subject: 'Zugriff entzogen',
|
||||
context: {
|
||||
firstName,
|
||||
systemName
|
||||
firstName: to.firstName,
|
||||
systemName: system.name
|
||||
}
|
||||
}).then(v => {
|
||||
this.logService.log(LogType.Mail, {
|
||||
to,
|
||||
success: true,
|
||||
message: v.response,
|
||||
type: EmailEvent.RemoveSystemAccess
|
||||
type: EmailEvent.RemoveSystemAccess,
|
||||
system
|
||||
})
|
||||
}).catch(e => {
|
||||
this.logService.log(LogType.Mail, {
|
||||
to,
|
||||
success: false,
|
||||
message: e.response,
|
||||
type: EmailEvent.RemoveSystemAccess
|
||||
type: EmailEvent.RemoveSystemAccess,
|
||||
system
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user