Mailservice
This commit is contained in:
68
api/src/modules/mail/mail.service.ts
Normal file
68
api/src/modules/mail/mail.service.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { MailerService } from "@nestjs-modules/mailer";
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { EmailEvent, LogService, LogType } from "../log/log.service";
|
||||
|
||||
@Injectable()
|
||||
export class MailService {
|
||||
constructor(
|
||||
private mailserService: MailerService,
|
||||
private readonly configService: ConfigService,
|
||||
private readonly logService: LogService,
|
||||
) {
|
||||
}
|
||||
|
||||
async sendAccessGrantedMail({to, firstName, systemName}: {to: string, firstName: string, systemName: string}) {
|
||||
this.mailserService.sendMail({
|
||||
template: './access',
|
||||
to: to,
|
||||
from: this.configService.get<string>('MAILER_FROM'),
|
||||
subject: 'Zugriff gewährt',
|
||||
context: {
|
||||
firstName,
|
||||
systemName
|
||||
}
|
||||
}).then(v => {
|
||||
this.logService.log(LogType.Mail, {
|
||||
to,
|
||||
success: true,
|
||||
message: v.response,
|
||||
type: EmailEvent.GrantSystemAccess
|
||||
})
|
||||
}).catch(e => {
|
||||
this.logService.log(LogType.Mail, {
|
||||
to,
|
||||
success: false,
|
||||
message: e.response,
|
||||
type: EmailEvent.GrantSystemAccess
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
sendAccessRemovedMail({to, firstName, systemName}: {to: string, firstName: string, systemName: string}) {
|
||||
this.mailserService.sendMail({
|
||||
template: './access-removed',
|
||||
to: to,
|
||||
from: this.configService.get<string>('MAILER_FROM'),
|
||||
subject: 'Zugriff entzogen',
|
||||
context: {
|
||||
firstName,
|
||||
systemName
|
||||
}
|
||||
}).then(v => {
|
||||
this.logService.log(LogType.Mail, {
|
||||
to,
|
||||
success: true,
|
||||
message: v.response,
|
||||
type: EmailEvent.RemoveSystemAccess
|
||||
})
|
||||
}).catch(e => {
|
||||
this.logService.log(LogType.Mail, {
|
||||
to,
|
||||
success: false,
|
||||
message: e.response,
|
||||
type: EmailEvent.RemoveSystemAccess
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user