forked from Xeio/IdleCodeRedeemer
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauditManager.ts
More file actions
57 lines (49 loc) · 1.6 KB
/
auditManager.ts
File metadata and controls
57 lines (49 loc) · 1.6 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { eq, gte, sql } from 'drizzle-orm';
import { db } from './db';
import { auditLog } from './schema/index';
type AuditLog = typeof auditLog.$inferSelect;
class AuditManager {
async logAction(discordId: string | null, action: string, details?: any): Promise<void> {
const detailsStr = details ? JSON.stringify(details) : null;
db.insert(auditLog).values({ discordId, action, details: detailsStr }).run();
}
async getUserAuditLog(discordId: string, limit: number = 50): Promise<AuditLog[]> {
return db
.select()
.from(auditLog)
.where(eq(auditLog.discordId, discordId))
.orderBy(sql`${auditLog.createdAt} DESC`)
.limit(limit)
.all();
}
async getAllAuditLog(limit: number = 100): Promise<AuditLog[]> {
return db
.select()
.from(auditLog)
.orderBy(sql`${auditLog.createdAt} DESC`)
.limit(limit)
.all();
}
async getAuditLogSince(timestamp: string, limit: number = 100): Promise<AuditLog[]> {
return db
.select()
.from(auditLog)
.where(gte(auditLog.createdAt, timestamp))
.orderBy(sql`${auditLog.createdAt} DESC`)
.limit(limit)
.all();
}
async getAuditLogByAction(action: string, limit: number = 50): Promise<AuditLog[]> {
return db
.select()
.from(auditLog)
.where(eq(auditLog.action, action))
.orderBy(sql`${auditLog.createdAt} DESC`)
.limit(limit)
.all();
}
async deleteUserAuditLog(discordId: string): Promise<void> {
db.delete(auditLog).where(eq(auditLog.discordId, discordId)).run();
}
}
export const auditManager = new AuditManager();