From 0129f5623c15d04859ec6a2a50978a0317e02392 Mon Sep 17 00:00:00 2001 From: saravanakumardb1 Date: Mon, 13 Apr 2026 15:52:49 -0700 Subject: [PATCH] fix(backend): emit routine.started and household.created domain events Event bus defines 6 event types but only timer.created was wired. Wire the two straightforward create/start events: - routine.started: emitted from POST /routines/:id/start - household.created: emitted from POST /households --- backend/src/modules/households/routes.ts | 2 ++ backend/src/modules/routines/routes.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/backend/src/modules/households/routes.ts b/backend/src/modules/households/routes.ts index a8a5cb6..86bca2b 100644 --- a/backend/src/modules/households/routes.ts +++ b/backend/src/modules/households/routes.ts @@ -16,6 +16,7 @@ import crypto from 'node:crypto'; import type { FastifyInstance } from 'fastify'; import { BadRequestError, NotFoundError, ForbiddenError, ConflictError } from '@bytelyst/errors'; import { extractAuth } from '../../lib/auth.js'; +import { getEventBus } from '../../lib/event-bus.js'; import * as repo from './repository.js'; import { CreateHouseholdSchema, @@ -95,6 +96,7 @@ export async function householdRoutes(app: FastifyInstance) { req.log.info({ householdId: doc.id }, 'Creating household'); const created = await repo.createHousehold(doc); + getEventBus().emit('household.created', { householdId: doc.id, userId: auth.sub, name: doc.name }); reply.code(201); return created; }); diff --git a/backend/src/modules/routines/routes.ts b/backend/src/modules/routines/routes.ts index f624b97..2673942 100644 --- a/backend/src/modules/routines/routes.ts +++ b/backend/src/modules/routines/routes.ts @@ -13,6 +13,7 @@ import type { FastifyInstance } from 'fastify'; import { BadRequestError, NotFoundError, ConflictError } from '@bytelyst/errors'; import { extractAuth } from '../../lib/auth.js'; +import { getEventBus } from '../../lib/event-bus.js'; import { isFeatureEnabled } from '../../lib/feature-flags.js'; import * as repo from './repository.js'; import { @@ -186,6 +187,7 @@ export async function routineRoutes(app: FastifyInstance) { } if (!result.doc) throw new NotFoundError('Routine not found'); + getEventBus().emit('routine.started', { routineId: id, userId: auth.sub, name: routine.name }); req.log.info({ routineId: id }, 'Started routine'); return result.doc; });