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:
@@ -1,37 +1,26 @@
|
||||
import { Injectable, Logger } from "@nestjs/common";
|
||||
import { desc, eq } from "drizzle-orm";
|
||||
import { DatabaseService } from "../database/database.service";
|
||||
import { reports } from "../database/schemas";
|
||||
import { ReportsRepository } from "./repositories/reports.repository";
|
||||
import { CreateReportDto } from "./dto/create-report.dto";
|
||||
|
||||
@Injectable()
|
||||
export class ReportsService {
|
||||
private readonly logger = new Logger(ReportsService.name);
|
||||
|
||||
constructor(private readonly databaseService: DatabaseService) {}
|
||||
constructor(private readonly reportsRepository: ReportsRepository) {}
|
||||
|
||||
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;
|
||||
return await this.reportsRepository.create({
|
||||
reporterId,
|
||||
contentId: data.contentId,
|
||||
tagId: data.tagId,
|
||||
reason: data.reason,
|
||||
description: data.description,
|
||||
});
|
||||
}
|
||||
|
||||
async findAll(limit: number, offset: number) {
|
||||
return await this.databaseService.db
|
||||
.select()
|
||||
.from(reports)
|
||||
.orderBy(desc(reports.createdAt))
|
||||
.limit(limit)
|
||||
.offset(offset);
|
||||
return await this.reportsRepository.findAll(limit, offset);
|
||||
}
|
||||
|
||||
async updateStatus(
|
||||
@@ -39,10 +28,6 @@ export class ReportsService {
|
||||
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();
|
||||
return await this.reportsRepository.updateStatus(id, status);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user