Files
TREK/server/src/db/entities/AuditLog.entity.ts
T

33 lines
866 B
TypeScript

import { Users } from './Users.entity';
import { defineEntity, p, type Ref, EntityRepository } from '@mikro-orm/core';
export class AuditLog {
id?: number | null;
createdAt?: Date | null;
user?: Ref<Users> | null;
action!: string;
resource?: string | null;
details?: string | null;
ip?: string | null;
}
export class AuditLogRepository extends EntityRepository<AuditLog> {}
export const AuditLogSchema = defineEntity({
class: AuditLog,
repository: () => AuditLogRepository,
properties: {
id: p.integer().primary().autoincrement(),
createdAt: p
.datetime()
.nullable()
.onCreate(() => new Date())
.index('idx_audit_log_created'),
user: () => p.manyToOne(Users).ref().nullable(),
action: p.text(),
resource: p.text().nullable(),
details: p.text().nullable(),
ip: p.text().nullable(),
},
});