feat: add logging and caching enhancements across core services

Integrate `Logger` for consistent logging in services like `reports`, `categories`, `users`, `contents`, and more. Introduce caching capabilities with `CacheInterceptor` and manual cache clearing logic for categories, users, and contents. Add request throttling to critical auth endpoints for enhanced rate limiting.
This commit is contained in:
Mathis HERRIOT
2026-01-10 16:31:06 +01:00
parent 9654553940
commit 5a22ad7480
12 changed files with 129 additions and 13 deletions

View File

@@ -1,14 +1,17 @@
import { createHash, randomBytes } from "node:crypto";
import { Injectable } from "@nestjs/common";
import { Injectable, Logger } from "@nestjs/common";
import { and, eq } from "drizzle-orm";
import { DatabaseService } from "../database/database.service";
import { apiKeys } from "../database/schemas";
@Injectable()
export class ApiKeysService {
private readonly logger = new Logger(ApiKeysService.name);
constructor(private readonly databaseService: DatabaseService) {}
async create(userId: string, name: string, expiresAt?: Date) {
this.logger.log(`Creating API key for user ${userId}: ${name}`);
const prefix = "mg_live_";
const randomPart = randomBytes(24).toString("hex");
const key = `${prefix}${randomPart}`;
@@ -46,6 +49,7 @@ export class ApiKeysService {
}
async revoke(userId: string, keyId: string) {
this.logger.log(`Revoking API key ${keyId} for user ${userId}`);
return await this.databaseService.db
.update(apiKeys)
.set({ isActive: false, updatedAt: new Date() })