Backend NestJS/Prisma, application mobile Expo (Tap to Pay Stripe), tableau de bord web Vite et documentation (cadrage en brouillon, décisions d'architecture). Secrets et fichiers locaux exclus par .gitignore. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
34 lines
989 B
TypeScript
34 lines
989 B
TypeScript
import { Injectable, Logger } from '@nestjs/common';
|
|
import { Prisma } from '@prisma/client';
|
|
import { PrismaService } from '../prisma/prisma.service';
|
|
|
|
export interface AuditEntry {
|
|
userId?: string | null;
|
|
action: string;
|
|
ip?: string | null;
|
|
/** Ne jamais y mettre de secret, mot de passe, token ou donnée bancaire. */
|
|
metadata?: Prisma.InputJsonValue;
|
|
}
|
|
|
|
@Injectable()
|
|
export class AuditService {
|
|
private readonly logger = new Logger(AuditService.name);
|
|
|
|
constructor(private readonly prisma: PrismaService) {}
|
|
|
|
async log(entry: AuditEntry): Promise<void> {
|
|
try {
|
|
await this.prisma.auditLog.create({
|
|
data: {
|
|
userId: entry.userId ?? null,
|
|
action: entry.action,
|
|
ip: entry.ip ?? null,
|
|
metadata: entry.metadata,
|
|
},
|
|
});
|
|
} catch (err) {
|
|
// L'audit ne doit jamais faire échouer l'opération métier.
|
|
this.logger.error(`Échec écriture audit "${entry.action}"`, err as Error);
|
|
}
|
|
}
|
|
}
|