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
This commit is contained in:
saravanakumardb1 2026-04-13 15:52:49 -07:00
parent 9b398bbd68
commit 0129f5623c
2 changed files with 4 additions and 0 deletions

View File

@ -16,6 +16,7 @@ import crypto from 'node:crypto';
import type { FastifyInstance } from 'fastify'; import type { FastifyInstance } from 'fastify';
import { BadRequestError, NotFoundError, ForbiddenError, ConflictError } from '@bytelyst/errors'; import { BadRequestError, NotFoundError, ForbiddenError, ConflictError } from '@bytelyst/errors';
import { extractAuth } from '../../lib/auth.js'; import { extractAuth } from '../../lib/auth.js';
import { getEventBus } from '../../lib/event-bus.js';
import * as repo from './repository.js'; import * as repo from './repository.js';
import { import {
CreateHouseholdSchema, CreateHouseholdSchema,
@ -95,6 +96,7 @@ export async function householdRoutes(app: FastifyInstance) {
req.log.info({ householdId: doc.id }, 'Creating household'); req.log.info({ householdId: doc.id }, 'Creating household');
const created = await repo.createHousehold(doc); const created = await repo.createHousehold(doc);
getEventBus().emit('household.created', { householdId: doc.id, userId: auth.sub, name: doc.name });
reply.code(201); reply.code(201);
return created; return created;
}); });

View File

@ -13,6 +13,7 @@
import type { FastifyInstance } from 'fastify'; import type { FastifyInstance } from 'fastify';
import { BadRequestError, NotFoundError, ConflictError } from '@bytelyst/errors'; import { BadRequestError, NotFoundError, ConflictError } from '@bytelyst/errors';
import { extractAuth } from '../../lib/auth.js'; import { extractAuth } from '../../lib/auth.js';
import { getEventBus } from '../../lib/event-bus.js';
import { isFeatureEnabled } from '../../lib/feature-flags.js'; import { isFeatureEnabled } from '../../lib/feature-flags.js';
import * as repo from './repository.js'; import * as repo from './repository.js';
import { import {
@ -186,6 +187,7 @@ export async function routineRoutes(app: FastifyInstance) {
} }
if (!result.doc) throw new NotFoundError('Routine not found'); 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'); req.log.info({ routineId: id }, 'Started routine');
return result.doc; return result.doc;
}); });