feat(email): send trial ending soon mails

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-03-30 20:58:17 +02:00
parent 0f0bb13107
commit a9c664dcfb
12 changed files with 1143 additions and 123 deletions

View File

@@ -0,0 +1,50 @@
import { db } from '@openpanel/db';
import { sendEmail } from '@openpanel/email';
import type { MiscQueuePayloadTrialEndingSoon } from '@openpanel/queue';
import type { Job } from 'bullmq';
export async function trialEndingSoonJob(
job: Job<MiscQueuePayloadTrialEndingSoon>,
) {
const { organizationId } = job.data.payload;
const organization = await db.organization.findUnique({
where: {
id: organizationId,
},
include: {
createdBy: {
select: {
email: true,
},
},
projects: {
select: {
id: true,
},
},
},
});
if (!organization) {
return;
}
const project = organization.projects[0];
if (!organization.createdBy?.email) {
return;
}
if (!project) {
return;
}
return sendEmail('trial-ending-soon', {
to: organization.createdBy?.email,
data: {
organizationName: organization.name,
url: `https://dashboard.openpanel.dev/${organization.id}/${project.id}/settings/organization?tab=billing`,
},
});
}

View File

@@ -0,0 +1,13 @@
import type { Job } from 'bullmq';
import type { MiscQueuePayloadTrialEndingSoon } from '@openpanel/queue';
import { trialEndingSoonJob } from './misc.trail-ending-soon';
export async function miscJob(job: Job<MiscQueuePayloadTrialEndingSoon>) {
switch (job.data.type) {
case 'trialEndingSoon': {
return await trialEndingSoonJob(job);
}
}
}