feat(marketing-pages): sendWelcomeEmail job + handler enqueues it
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.
This commit is contained in:
@@ -19,6 +19,9 @@ import type { IPagesRepository } from "../application/repositories/pages.reposit
|
||||
import type { ISiteSettingsRepository } from "../application/repositories/site-settings.repository.interface.js";
|
||||
import { userSignedUpEvent } from "@repo/auth";
|
||||
import { onAuthUserSignedUpHandler } from "../events/handlers/on-auth-user-signed-up.handler.js";
|
||||
import { sendWelcomeEmailJob, type ISendWelcomeEmailJob, type SendWelcomeEmailInput } from "../jobs/send-welcome-email.job.js";
|
||||
import { RecordingMailerService } from "../infrastructure/services/recording-mailer.service.js";
|
||||
import type { IMailerService } from "../application/services/mailer.service.interface.js";
|
||||
|
||||
/**
|
||||
* Replace the default empty mocks with populated ones for dev mode + storybook.
|
||||
@@ -129,10 +132,15 @@ export async function bindDevSeedMarketingPages(
|
||||
),
|
||||
),
|
||||
);
|
||||
// bus + queue are accept-and-forward in Phase 6; consumed by Phase 7 generator
|
||||
// output at the <gen:event-handlers> / <gen:jobs> anchors below.
|
||||
void bus;
|
||||
void queue;
|
||||
// Bind the dev-seed mailer (recording so e2e tests can inspect calls).
|
||||
if (marketingPagesContainer.isBound(MARKETING_PAGES_SYMBOLS.IMailerService)) {
|
||||
marketingPagesContainer.unbind(MARKETING_PAGES_SYMBOLS.IMailerService);
|
||||
}
|
||||
const mailer = new RecordingMailerService();
|
||||
marketingPagesContainer
|
||||
.bind<IMailerService>(MARKETING_PAGES_SYMBOLS.IMailerService)
|
||||
.toConstantValue(mailer);
|
||||
|
||||
// <gen:event-handlers>
|
||||
// onAuthUserSignedUpHandler subscription — generated, edit the handler file (not this block) for behavior.
|
||||
const wrappedAuthUserSignedUp = withSpan(
|
||||
@@ -145,7 +153,7 @@ export async function bindDevSeedMarketingPages(
|
||||
layer: "event-handler",
|
||||
name: "marketing-pages.onAuthUserSignedUpHandler",
|
||||
},
|
||||
onAuthUserSignedUpHandler(),
|
||||
onAuthUserSignedUpHandler(queue),
|
||||
),
|
||||
);
|
||||
if (marketingPagesContainer.isBound(MARKETING_PAGES_SYMBOLS.IOnAuthUserSignedUpHandler)) {
|
||||
@@ -154,4 +162,35 @@ export async function bindDevSeedMarketingPages(
|
||||
marketingPagesContainer.bind(MARKETING_PAGES_SYMBOLS.IOnAuthUserSignedUpHandler).toConstantValue(wrappedAuthUserSignedUp);
|
||||
bus.subscribe(userSignedUpEvent, "marketing-pages", wrappedAuthUserSignedUp);
|
||||
// <gen:jobs>
|
||||
const wrappedSendWelcomeEmail = withSpan(
|
||||
tracer,
|
||||
{ name: "marketing-pages.sendWelcomeEmail", op: "job" },
|
||||
withCapture(
|
||||
logger,
|
||||
{
|
||||
feature: "marketing-pages",
|
||||
layer: "job",
|
||||
name: "marketing-pages.sendWelcomeEmail",
|
||||
},
|
||||
sendWelcomeEmailJob(mailer),
|
||||
),
|
||||
);
|
||||
if (marketingPagesContainer.isBound(MARKETING_PAGES_SYMBOLS.ISendWelcomeEmailJob)) {
|
||||
marketingPagesContainer.unbind(MARKETING_PAGES_SYMBOLS.ISendWelcomeEmailJob);
|
||||
}
|
||||
marketingPagesContainer.bind(MARKETING_PAGES_SYMBOLS.ISendWelcomeEmailJob).toConstantValue(wrappedSendWelcomeEmail);
|
||||
|
||||
// Register the dev-seed in-memory queue handler so enqueue() actually fires
|
||||
// the wrapped job. Production binding skips this — the Payload task does it.
|
||||
if ("register" in queue && typeof (queue as { register?: unknown }).register === "function") {
|
||||
(queue as { register: (slug: string, h: (input: unknown) => Promise<void>) => void }).register(
|
||||
"marketing-pages.send-welcome-email",
|
||||
async (input) => {
|
||||
const wrapped = marketingPagesContainer.get<ISendWelcomeEmailJob>(
|
||||
MARKETING_PAGES_SYMBOLS.ISendWelcomeEmailJob,
|
||||
);
|
||||
await wrapped(input as SendWelcomeEmailInput);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user