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; });