add security loop

This commit is contained in:
Emily
2024-09-26 15:48:59 +02:00
parent f5edf187fd
commit 3b1ee0fd13
4 changed files with 10 additions and 27 deletions

View File

@@ -1,4 +1,4 @@
import { anomalyCheckAll, AnomalyReport, findAnomalies } from "./AnomalyService";
import { anomalyLoop } from "./AnomalyService";
import { connectDatabase } from '@services/DatabaseService'
import { requireEnv } from '@utils/requireEnv'
@@ -10,37 +10,18 @@ import { UserModel } from "@schema/UserSchema";
EmailService.init(requireEnv('BREVO_API_KEY'));
connectDatabase(requireEnv('MONGO_CONNECTION_STRING'));
anomalyCheckAll(async report => {
anomalyLoop(async report => {
if (report.visits.length > 0 || report.events.length > 0 || report.dns.length > 0) {
const project = await ProjectModel.findById(report.pid);
if (!project) return { ok: false, error: 'Cannot find project with id ' + report.pid.toString() }
const user = await UserModel.findById(project.owner);
if (!user) return { ok: false, error: 'Cannot find user with id ' + project.owner.toString() }
if (report.visits.length > 0 || report.events.length > 0) {
await EmailService.sendAnomalyVisitsEventsEmail(
user.email,
project.name,
{ visits: report.visits, events: report.events }
);
await EmailService.sendAnomalyVisitsEventsEmail(user.email, project.name, { visits: report.visits, events: report.events });
}
if (report.visits.length > 0) {
await EmailService.sendAnomalyDomainEmail(
user.email,
project.name,
report.dns
);
await EmailService.sendAnomalyDomainEmail(user.email, project.name, report.dns);
}
}
});
})