feat(email): send trial ending soon mails
This commit is contained in:
50
apps/worker/src/jobs/misc.trail-ending-soon.ts
Normal file
50
apps/worker/src/jobs/misc.trail-ending-soon.ts
Normal 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`,
|
||||
},
|
||||
});
|
||||
}
|
||||
13
apps/worker/src/jobs/misc.ts
Normal file
13
apps/worker/src/jobs/misc.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user