forked from Nova-reward/Nova-Rewards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudit.service.ts
More file actions
37 lines (34 loc) · 932 Bytes
/
Copy pathaudit.service.ts
File metadata and controls
37 lines (34 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { AuditLog } from './audit.entity';
@Injectable()
export class AuditService {
constructor(
@InjectRepository(AuditLog)
private auditRepository: Repository<AuditLog>,
) {}
async log(
action: string,
userId: string,
adminId: string,
reason?: string,
metadata?: Record<string, any>,
): Promise<void> {
const log = this.auditRepository.create({
action,
userId,
adminId,
reason,
metadata,
});
await this.auditRepository.save(log);
}
async getAuditLogs(userId?: string): Promise<AuditLog[]> {
const query = this.auditRepository.createQueryBuilder('audit');
if (userId) {
query.where('audit.userId = :userId', { userId });
}
return query.orderBy('audit.createdAt', 'DESC').getMany();
}
}