@ideal-photography/shared
Version:
Shared MongoDB and utility logic for Ideal Photography PWAs: users, products, services, bookings, orders/cart, galleries, reviews, notifications, campaigns, settings, audit logs, minimart items/orders, and push notification subscriptions.
25 lines (21 loc) • 820 B
JavaScript
import * as auth from './auth.js';
import * as bookings from './bookings.js';
import * as errors from './errors.js';
import AlertBus from '../AlertBus.js';
import NotificationService from '../../services/NotificationService.js';
const handlers = { auth, bookings, error: errors };
// Register global listener
AlertBus.on('alert', async ({ trigger, payload, opts }) => {
try {
const [group, name] = trigger.split('.');
const mod = handlers[group];
const fn = mod?.[name];
if (typeof fn === 'function') {
const alertMeta = fn(payload);
await NotificationService.createAndSend(alertMeta, { ...opts, trigger });
}
} catch (err) {
console.error('Alert handler error', trigger, err);
}
});
export default handlers;