sendWelcomeEmailJob takes IMailerService, validates the typed input (userId + email), and delegates to mailer.sendWelcome. The onAuthUserSignedUpHandler now takes IJobQueue and enqueues "marketing-pages.send-welcome-email" with the event payload. Both binders bind a RecordingMailerService at the IMailerService symbol (production placeholder until a real adapter ships) and pass mailer / queue into the wrapped factories. Dev-seed additionally queue.register()s the slug so the in-memory queue dispatches via the wrapped job; production relies on the generated Payload event-task to resolve the wrapped handler from the container.
21 lines
697 B
TypeScript
21 lines
697 B
TypeScript
// packages/marketing-pages/src/jobs/send-welcome-email.job.ts
|
|
import { z } from "zod";
|
|
import type { IMailerService } from "../application/services/mailer.service.interface";
|
|
|
|
export const sendWelcomeEmailInputSchema = z
|
|
.object({
|
|
userId: z.string(),
|
|
email: z.string().email(),
|
|
})
|
|
.strict();
|
|
|
|
export type SendWelcomeEmailInput = z.infer<typeof sendWelcomeEmailInputSchema>;
|
|
export type ISendWelcomeEmailJob = ReturnType<typeof sendWelcomeEmailJob>;
|
|
|
|
export const sendWelcomeEmailJob =
|
|
(mailer: IMailerService) =>
|
|
async (input: SendWelcomeEmailInput): Promise<void> => {
|
|
sendWelcomeEmailInputSchema.parse(input);
|
|
await mailer.sendWelcome(input.userId, input.email);
|
|
};
|