add broker

This commit is contained in:
Litlyx
2024-05-31 14:08:51 +02:00
parent 2b185a9db5
commit 9caec3b92b
17 changed files with 489415 additions and 0 deletions

20
broker/src/Controller.ts Normal file
View File

@@ -0,0 +1,20 @@
import { TProjectCount } from "@schema/ProjectsCounts";
import { ProjectModel } from "@schema/ProjectSchema";
import { UserModel } from "@schema/UserSchema";
import { LimitNotifyModel } from "@schema/broker/LimitNotifySchema";
import { sendLimitEmail50 } from '@services/EmailService';
export async function checkLimitsForEmail(projectCounts: TProjectCount) {
if ((projectCounts.visits + projectCounts.events) >= (projectCounts.limit / 2)) {
const notify = await LimitNotifyModel.findOne({ project_id: projectCounts._id });
if (notify && notify.limit1 === true) return;
const project = await ProjectModel.findById(projectCounts.project_id);
if (!project) return;
const owner = await UserModel.findById(project.owner);
if (!owner) return;
await sendLimitEmail50(owner.email);
await LimitNotifyModel.updateOne({ project_id: projectCounts._id }, { limit1: true, limit2: false, limit3: false }, { upsert: true });
}
}