48 lines
963 B
TypeScript
48 lines
963 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { User } from 'src/model/entitites';
|
|
import { EmailLogRepository } from 'src/model/repositories/log';
|
|
|
|
@Injectable()
|
|
export class LogService {
|
|
constructor(private readonly emailLogRepo: EmailLogRepository) {
|
|
}
|
|
|
|
|
|
|
|
log(type: LogType, data: any) {
|
|
if (type == LogType.Mail) {
|
|
return this.logEmail(data);
|
|
} else if (type == LogType.Auth) {
|
|
return this.logAuthEvent(data);
|
|
}
|
|
}
|
|
|
|
private async logEmail(data: EmailLogDto) {
|
|
const log = this.emailLogRepo.create(data);
|
|
const logEntry = await this.emailLogRepo.save(log);
|
|
}
|
|
|
|
private async logAuthEvent(data: User) {
|
|
// console.error("auth logging not implemented")
|
|
}
|
|
}
|
|
|
|
export enum LogType {
|
|
Mail,
|
|
Auth
|
|
}
|
|
|
|
export enum EmailEvent {
|
|
GrantSystemAccess,
|
|
RemoveSystemAccess,
|
|
KeyHandout,
|
|
KeyLostOrFound
|
|
}
|
|
|
|
export interface EmailLogDto {
|
|
success: boolean;
|
|
message: string;
|
|
to: string;
|
|
type: EmailEvent;
|
|
}
|