Archive und Logging
This commit is contained in:
@@ -10,10 +10,52 @@ export class MailService {
|
||||
constructor(
|
||||
private mailserService: MailerService,
|
||||
private readonly configService: ConfigService,
|
||||
private readonly logService: LogService,
|
||||
private readonly logService: LogService
|
||||
) {
|
||||
}
|
||||
|
||||
async sendKeyLostOrFoundMail({to, key}: {to: User, key: Key}) {
|
||||
// const subject
|
||||
const keyAction = key.keyLost == null ? 'wurde gefunden' : 'wurde als verloren gemeldet';
|
||||
const keyExtendedAction = key.keyLost == null ? `wurde als gefunden gemeldet` : `wurde am ${new Date(key.keyLost).toLocaleDateString()} als verloren gemeldet`;
|
||||
const subject = key.keyLost == null ? 'Schlüssel gefunden' : 'Schlüssel verloren';
|
||||
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.KeyLostOrFound,
|
||||
system: key.cylinder[0].system,
|
||||
context: JSON.stringify(key)
|
||||
})
|
||||
}).catch(e => {
|
||||
this.logService.log(LogType.Mail, {
|
||||
to,
|
||||
success: false,
|
||||
message: e.response,
|
||||
type: EmailEvent.KeyLostOrFound,
|
||||
system: key.cylinder[0].system,
|
||||
context: JSON.stringify(key)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
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`;
|
||||
|
||||
Reference in New Issue
Block a user