feat: add modular services and repositories for improved code organization
Introduce repository pattern across multiple services, including `favorites`, `tags`, `sessions`, `reports`, `auth`, and more. Decouple crypto functionalities into modular services like `HashingService`, `JwtService`, and `EncryptionService`. Improve testability and maintainability by simplifying dependencies and consolidating utility logic.
This commit is contained in:
50
backend/src/reports/repositories/reports.repository.ts
Normal file
50
backend/src/reports/repositories/reports.repository.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { desc, eq, lte } from "drizzle-orm";
|
||||
import { DatabaseService } from "../../database/database.service";
|
||||
import { reports } from "../../database/schemas";
|
||||
|
||||
@Injectable()
|
||||
export class ReportsRepository {
|
||||
constructor(private readonly databaseService: DatabaseService) {}
|
||||
|
||||
async create(data: {
|
||||
reporterId: string;
|
||||
contentId?: string;
|
||||
tagId?: string;
|
||||
reason: string;
|
||||
description?: string;
|
||||
}) {
|
||||
const [newReport] = await this.databaseService.db
|
||||
.insert(reports)
|
||||
.values(data)
|
||||
.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();
|
||||
}
|
||||
|
||||
async purgeObsolete(now: Date) {
|
||||
return await this.databaseService.db
|
||||
.delete(reports)
|
||||
.where(lte(reports.expiresAt, now))
|
||||
.returning();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user