more package declarations
This commit is contained in:
@@ -75,16 +75,42 @@ async function processReportGeneration(
|
||||
|
||||
const userName = user?.name || notifyEmail.split('@')[0];
|
||||
|
||||
await emailService.sendWithTemplate(notifyEmail, {
|
||||
templateId: 'report_ready',
|
||||
variables: {
|
||||
name: userName,
|
||||
report_title: report.title,
|
||||
report_summary: report.summary || 'Your protection report contains detailed statistics and recommendations.',
|
||||
report_url: `${dashboardUrl}/reports/${report.id}`,
|
||||
pdf_url: report.pdfUrl || `${dashboardUrl}/api/v1/reports/${report.id}/pdf`,
|
||||
},
|
||||
});
|
||||
const templateId = report.reportType === 'WEEKLY_DIGEST' ? 'weekly_digest' : 'report_ready';
|
||||
|
||||
if (report.reportType === 'WEEKLY_DIGEST' && report.dataPayload) {
|
||||
const payload = typeof report.dataPayload === 'string' ? JSON.parse(report.dataPayload) : report.dataPayload;
|
||||
|
||||
await emailService.sendWithTemplate(notifyEmail, {
|
||||
templateId: 'weekly_digest',
|
||||
variables: {
|
||||
name: userName,
|
||||
period_start: new Date(report.periodStart).toLocaleDateString('en-US', { month: 'long', day: 'numeric' }),
|
||||
period_end: new Date(report.periodEnd).toLocaleDateString('en-US', { month: 'long', day: 'numeric' }),
|
||||
protection_score: payload.protectionScore || 0,
|
||||
new_exposures: payload.exposureSummary?.newExposures || 0,
|
||||
critical_exposures: payload.exposureSummary?.criticalExposures || 0,
|
||||
spam_events_blocked: payload.spamStats?.totalSpamEvents || 0,
|
||||
calls_blocked: payload.spamStats?.callsBlocked || 0,
|
||||
texts_blocked: payload.spamStats?.textsBlocked || 0,
|
||||
voice_threats: payload.voiceStats?.threatsDetected || 0,
|
||||
enrollments_active: payload.voiceStats?.enrollmentsActive || 0,
|
||||
properties_monitored: payload.homeTitleStats?.propertiesMonitored || 0,
|
||||
changes_detected: payload.homeTitleStats?.changesDetected || 0,
|
||||
report_url: `${dashboardUrl}/reports/${report.id}`,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
await emailService.sendWithTemplate(notifyEmail, {
|
||||
templateId: 'report_ready',
|
||||
variables: {
|
||||
name: userName,
|
||||
report_title: report.title,
|
||||
report_summary: report.summary || 'Your protection report contains detailed statistics and recommendations.',
|
||||
report_url: `${dashboardUrl}/reports/${report.id}`,
|
||||
pdf_url: report.pdfUrl || `${dashboardUrl}/api/v1/reports/${report.id}/pdf`,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
await prisma.securityReport.update({
|
||||
where: { id: report.id },
|
||||
@@ -245,6 +271,13 @@ export async function scheduleMonthlyReportTrigger() {
|
||||
});
|
||||
}
|
||||
|
||||
export async function scheduleWeeklyDigestTrigger() {
|
||||
return reportSchedulerQueue.add('trigger-weekly-digest', {}, {
|
||||
repeat: { pattern: '0 8 * * 1' },
|
||||
jobId: 'weekly-digest-trigger',
|
||||
});
|
||||
}
|
||||
|
||||
export async function scheduleAnnualReportTrigger() {
|
||||
return reportSchedulerQueue.add('trigger-annual-reports', {}, {
|
||||
repeat: { pattern: '0 0 1 1 *' },
|
||||
|
||||
Reference in New Issue
Block a user