feat: implement ReportsModule with service, controller, and endpoints

Added ReportsModule to manage user reports. Includes service methods for creating, retrieving, and updating report statuses, as well as controller endpoints for handling these operations. Integrated with authentication, role-based access control, and database logic.
This commit is contained in:
Mathis HERRIOT
2026-01-08 15:26:39 +01:00
parent dd875fe1ea
commit dde1bf522f
5 changed files with 149 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
import { Injectable } 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 {
constructor(private readonly databaseService: DatabaseService) {}
async create(reporterId: string, data: CreateReportDto) {
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",
) {
return await this.databaseService.db
.update(reports)
.set({ status, updatedAt: new Date() })
.where(eq(reports.id, id))
.returning();
}
}