database migrated to POSTGRESQL

This commit is contained in:
2026-10-13 16:11:51 +03:30
parent 41ad8c1063
commit 514c3ccaf0
47 changed files with 1500 additions and 891 deletions
+17 -14
View File
@@ -1,8 +1,9 @@
import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model, Types } from 'mongoose';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { AuditEvent } from '../common/enums/audit-event.enum';
import { AuditLog, AuditLogDocument } from './schemas/audit-log.schema';
import { isUuid } from '../database/postgres.helpers';
import { AuditLog } from './schemas/audit-log.schema';
export interface AuditContext {
userId?: string;
@@ -19,19 +20,21 @@ export interface AuditContext {
@Injectable()
export class AuditService {
constructor(
@InjectModel(AuditLog.name)
private readonly auditModel: Model<AuditLogDocument>,
@InjectRepository(AuditLog)
private readonly auditLogs: Repository<AuditLog>,
) {}
async log(event: AuditEvent, context: AuditContext = {}): Promise<void> {
await this.auditModel.create({
event,
userId: context.userId ? new Types.ObjectId(context.userId) : undefined,
actorId: context.actorId ? new Types.ObjectId(context.actorId) : undefined,
username: context.username,
ip: context.ip,
userAgent: context.userAgent,
metadata: context.metadata ?? {},
});
await this.auditLogs.save(
this.auditLogs.create({
event,
userId: isUuid(context.userId) ? context.userId : null,
actorId: isUuid(context.actorId) ? context.actorId : null,
username: context.username,
ip: context.ip,
userAgent: context.userAgent,
metadata: context.metadata ?? {},
}),
);
}
}