feat: certification rules, content sanitization, handle draft course updates and reset content, better redis logging

This commit is contained in:
Rotimi Best
2026-03-30 08:24:55 +01:00
parent ff2ad59377
commit 5a8f50f67b
131 changed files with 5643 additions and 2134 deletions
+3
View File
@@ -13,6 +13,7 @@ export * from './on-password-reset';
export * from './invite-teacher';
export * from './newsfeed';
export * from './student-course-welcome';
export * from './student-course-completion';
export * from './student-course-invite';
export * from './teacher-student-joined';
export * from './teacher-student-buy-request';
@@ -27,6 +28,7 @@ import type { forgotPasswordEmail } from './forgot-password';
import type { inviteTeacherEmail } from './invite-teacher';
import type { onPasswordResetEmail } from './on-password-reset';
import type { studentCourseInviteEmail } from './student-course-invite';
import type { studentCourseCompletionEmail } from './student-course-completion';
import type { studentCourseWelcomeEmail } from './student-course-welcome';
import type { studentProvePaymentEmail } from './student-prove-payment';
import type { studentOrgInviteEmail } from './student-org-invite';
@@ -51,6 +53,7 @@ export type EmailSchemas = {
newsfeedPost: typeof newsfeedPostEmail.template.schema;
newsfeedComment: typeof newsfeedCommentEmail.template.schema;
studentCourseWelcome: typeof studentCourseWelcomeEmail.template.schema;
studentCourseCompletion: typeof studentCourseCompletionEmail.template.schema;
studentCourseInvite: typeof studentCourseInviteEmail.template.schema;
teacherStudentJoined: typeof teacherStudentJoinedEmail.template.schema;
teacherStudentBuyRequest: typeof teacherStudentBuyRequestEmail.template.schema;
@@ -0,0 +1,33 @@
import * as z from 'zod';
import { defineEmail } from '../send';
import { getDefaultTemplate } from '../templates';
export const studentCourseCompletionEmail = defineEmail({
id: 'studentCourseCompletion',
subject: 'Congratulations — you completed the course requirements',
schema: z.object({
orgName: z.string().min(1),
courseName: z.string().min(1),
studentName: z.string().min(1),
certificateUrl: z.string().url(),
customMessage: z.string().nullable().optional()
}),
render: (fields) => {
const customBlock =
fields.customMessage && fields.customMessage.trim().length > 0
? `<div style="margin:16px 0;padding:12px;border-left:3px solid #6366f1;background:#f8fafc;">${fields.customMessage}</div>`
: '';
const content = `
<p>Hi ${fields.studentName},</p>
<p>Congratulations! You have met the completion requirements for <strong>${fields.courseName}</strong>.</p>
${customBlock}
<p><a href="${fields.certificateUrl}" style="display:inline-block;padding:10px 16px;background:#111827;color:#fff;text-decoration:none;border-radius:6px;">View your certificate</a></p>
<p>If the button does not work, copy and paste this link into your browser:<br/><span style="word-break:break-all;">${fields.certificateUrl}</span></p>
<p>Cheers,<br/>${fields.orgName}</p>
`;
return getDefaultTemplate(content);
}
});
@@ -5,17 +5,18 @@ import { getDefaultTemplate } from '../templates';
export const studentCourseWelcomeEmail = defineEmail({
id: 'studentCourseWelcome',
subject: 'Welcome to Class 🎉',
subject: 'You have access to a course — sign in to get started',
schema: z.object({
orgName: z.string().min(1),
courseName: z.string().min(1)
courseName: z.string().min(1),
loginUrl: z.string().min(1)
}),
render: (fields) => {
const content = `
<p>Hi there,</p>
<p>Congratulations 🎉, you've successfully joined: <strong>${fields.courseName}</strong></p>
<p>Everything has been set up for you to have an amazing learning experience.</p>
<p>If you run into any issues, don't fail to reach out to your instructor(s).</p>
<p>You now have access to <strong>${fields.courseName}</strong> in <strong>${fields.orgName}</strong>.</p>
<p><a href="${fields.loginUrl}">Sign in to ClassroomIO</a> to open the course and get started.</p>
<p>If you run into any issues, reach out to your instructor(s).</p>
<p>Cheers,</p>
<p>${fields.orgName}</p>
`;
+1
View File
@@ -7,6 +7,7 @@ export const EMAIL_IDS = [
'newsfeedPost',
'onPasswordReset',
'studentCourseInvite',
'studentCourseCompletion',
'studentCourseWelcome',
'studentOrgInvite',
'studentProvePayment',