68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
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
|
|
})
|
|
})
|
|
}
|
|
} |