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.
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { Injectable, Logger } from "@nestjs/common";
|
|
import { desc, eq } from "drizzle-orm";
|
|
import { DatabaseService } from "../database/database.service";
|
|
import { reports } from "../database/schemas";
|
|
import { CreateReportDto } from "./dto/create-report.dto";
|
|
|
|
@Injectable()
|
|
export class ReportsService {
|
|
private readonly logger = new Logger(ReportsService.name);
|
|
|
|
constructor(private readonly databaseService: DatabaseService) {}
|
|
|
|
async create(reporterId: string, data: CreateReportDto) {
|
|
this.logger.log(`Creating report from user ${reporterId}`);
|
|
const [newReport] = await this.databaseService.db
|
|
.insert(reports)
|
|
.values({
|
|
reporterId,
|
|
contentId: data.contentId,
|
|
tagId: data.tagId,
|
|
reason: data.reason,
|
|
description: data.description,
|
|
})
|
|
.returning();
|
|
return newReport;
|
|
}
|
|
|
|
async findAll(limit: number, offset: number) {
|
|
return await this.databaseService.db
|
|
.select()
|
|
.from(reports)
|
|
.orderBy(desc(reports.createdAt))
|
|
.limit(limit)
|
|
.offset(offset);
|
|
}
|
|
|
|
async updateStatus(
|
|
id: string,
|
|
status: "pending" | "reviewed" | "resolved" | "dismissed",
|
|
) {
|
|
this.logger.log(`Updating report ${id} status to ${status}`);
|
|
return await this.databaseService.db
|
|
.update(reports)
|
|
.set({ status, updatedAt: new Date() })
|
|
.where(eq(reports.id, id))
|
|
.returning();
|
|
}
|
|
}
|