mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
29 lines
1.2 KiB
TypeScript
29 lines
1.2 KiB
TypeScript
import { ProjectModel } from "@schema/ProjectSchema";
|
|
import { UserModel } from "@schema/UserSchema";
|
|
import { LimitNotifyModel } from "@schema/broker/LimitNotifySchema";
|
|
import EmailService from '@services/EmailService';
|
|
import { requireEnv } from "../../shared/utilts/requireEnv";
|
|
import { TProjectLimit } from "@schema/ProjectsLimits";
|
|
|
|
|
|
EmailService.createTransport(
|
|
requireEnv('EMAIL_SERVICE'),
|
|
requireEnv('EMAIL_HOST'),
|
|
requireEnv('EMAIL_USER'),
|
|
requireEnv('EMAIL_PASS'),
|
|
);
|
|
|
|
export async function checkLimitsForEmail(projectCounts: TProjectLimit) {
|
|
|
|
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 EmailService.sendLimitEmail50(owner.email);
|
|
await LimitNotifyModel.updateOne({ project_id: projectCounts._id }, { limit1: true, limit2: false, limit3: false }, { upsert: true });
|
|
}
|
|
|
|
} |