diff --git a/backend/api/controllers/quote.ts b/backend/api/controllers/quote.ts index f16132269..1754432c6 100644 --- a/backend/api/controllers/quote.ts +++ b/backend/api/controllers/quote.ts @@ -1,7 +1,7 @@ import _ from "lodash"; import { v4 as uuidv4 } from "uuid"; import { getUser, updateQuoteRatings } from "../../dao/user"; -import ReportDAO from "../../dao/report"; +import ReportDAL from "../../dao/report"; import * as NewQuotesDAL from "../../dao/new-quotes"; import QuoteRatingsDAO from "../../dao/quote-ratings"; import MonkeyError from "../../utils/error"; @@ -149,7 +149,7 @@ export async function reportQuote( comment, }; - await ReportDAO.createReport(newReport, maxReports, contentReportLimit); + await ReportDAL.createReport(newReport, maxReports, contentReportLimit); return new MonkeyResponse("Quote reported"); } diff --git a/backend/dao/report.ts b/backend/dao/report.ts index 7ceaab6a0..63f9322c3 100644 --- a/backend/dao/report.ts +++ b/backend/dao/report.ts @@ -3,37 +3,33 @@ import db from "../init/db"; const COLLECTION_NAME = "reports"; -class ReportDAO { - static async createReport( - report: MonkeyTypes.Report, - maxReports: number, - contentReportLimit: number - ): Promise { - const reportsCount = await db - .collection(COLLECTION_NAME) - .estimatedDocumentCount(); +export async function createReport( + report: MonkeyTypes.Report, + maxReports: number, + contentReportLimit: number +): Promise { + const reportsCount = await db + .collection(COLLECTION_NAME) + .estimatedDocumentCount(); - if (reportsCount >= maxReports) { - throw new MonkeyError( - 503, - "Reports are not being accepted at this time. Please try again later." - ); - } - - const sameReports = await db - .collection(COLLECTION_NAME) - .find({ contentId: report.contentId }) - .toArray(); - - if (sameReports.length >= contentReportLimit) { - throw new MonkeyError( - 409, - "A report limit for this content has been reached." - ); - } - - await db.collection(COLLECTION_NAME).insertOne(report); + if (reportsCount >= maxReports) { + throw new MonkeyError( + 503, + "Reports are not being accepted at this time. Please try again later." + ); } -} -export default ReportDAO; + const sameReports = await db + .collection(COLLECTION_NAME) + .find({ contentId: report.contentId }) + .toArray(); + + if (sameReports.length >= contentReportLimit) { + throw new MonkeyError( + 409, + "A report limit for this content has been reached." + ); + } + + await db.collection(COLLECTION_NAME).insertOne(report); +}