fix: ( notification ) add notification templet and fix issues

This commit is contained in:
Abubeker Yasin
2026-06-19 06:12:46 +03:00
parent f1dfbbcc3f
commit 42c020c97a
6 changed files with 75 additions and 31 deletions

View File

@@ -550,18 +550,22 @@ async function seedSegmentFares() {
async function seedNotificationTemplates() {
console.log('\n🔔 Seeding notification templates...');
// NOTE: `code` must match the templateKey passed by NotificationsService.send(...).
// The event-driven handlers use the dotted event names (booking.created, payment.succeeded).
const templates = [
{ id: uuidv4(), code: 'BOOKING_CONFIRMED', channel: 'EMAIL', subject: 'Booking Confirmed', bodyTemplate: 'Your booking {{bookingRef}} is confirmed for {{date}}' },
{ id: uuidv4(), code: 'PAYMENT_RECEIVED', channel: 'SMS', bodyTemplate: 'Payment ETB {{amount}} received for {{bookingRef}}' },
{ id: uuidv4(), code: 'TRIP_DEPARTURE', channel: 'PUSH', bodyTemplate: 'Your trip {{route}} departs in {{minutes}} minutes' },
{ id: uuidv4(), code: 'TRIP_DELAY', channel: 'EMAIL', subject: 'Trip Delayed', bodyTemplate: 'Your trip {{route}} is delayed by {{delayMinutes}} minutes' },
{ id: uuidv4(), code: 'PROMOTION', channel: 'PUSH', bodyTemplate: 'Get {{percentOff}}% off on {{route}}' },
{ id: uuidv4(), code: 'booking.created', channel: 'EMAIL', subject: 'Booking Confirmed', bodyTemplate: 'Your booking {{bookingRef}} is confirmed. Total: {{amount}} {{currency}}.' },
{ id: uuidv4(), code: 'payment.succeeded', channel: 'SMS', subject: 'Payment Received', bodyTemplate: 'Payment of {{amount}} {{currency}} received for booking {{bookingRef}}.' },
// Templates below are not wired to handlers yet (Phase 2 — full event coverage).
{ id: uuidv4(), code: 'trip.departure', channel: 'PUSH', subject: 'Trip Departing Soon', bodyTemplate: 'Your trip {{route}} departs in {{minutes}} minutes' },
{ id: uuidv4(), code: 'trip.delay', channel: 'EMAIL', subject: 'Trip Delayed', bodyTemplate: 'Your trip {{route}} is delayed by {{delayMinutes}} minutes' },
{ id: uuidv4(), code: 'promotion.offer', channel: 'PUSH', subject: 'Special Offer', bodyTemplate: 'Get {{percentOff}}% off on {{route}}' },
];
for (const t of templates) {
await prisma.notificationTemplate.upsert({
where: { code: t.code },
update: {},
// Refresh the editable fields on re-seed so template tweaks actually take effect.
update: { channel: t.channel, subject: t.subject ?? null, bodyTemplate: t.bodyTemplate, active: true },
create: t,
});
}
@@ -684,7 +688,8 @@ async function main() {
['system users', seedSystemUsers],
['fare rules', seedFareRules],
['segment fares', seedSegmentFares],
['currency', seedCurrency]
['currency', seedCurrency],
['notification templates', seedNotificationTemplates]
];
let failed = 0;