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:
parent
9b398bbd68
commit
0129f5623c
@ -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;
|
||||
});
|
||||
|
||||
@ -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;
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user