feat: improve notifications - fix auth code tg duplicate, double order notify, add PAID label, expand text, add deliveryFeeAdjusted event
This commit is contained in:
@@ -113,9 +113,26 @@ const {
|
||||
ORDER_MESSAGE_ADMIN_REPLY,
|
||||
PAYMENT_STATUS_CHANGED,
|
||||
AUTH_CODE_REQUESTED,
|
||||
DELIVERY_FEE_ADJUSTED,
|
||||
} = NOTIFICATION_EVENTS;
|
||||
|
||||
async function dispatchNotification(eventType, payload) {
|
||||
if (eventType === AUTH_CODE_REQUESTED) {
|
||||
const targets = await resolveAuthCodeTargets(eventType, payload);
|
||||
for (const target of targets.filter((t) => t.channel === 'telegram')) {
|
||||
const log = await prisma.notificationLog.create({
|
||||
data: {
|
||||
eventType,
|
||||
channel: target.channel,
|
||||
status: 'pending',
|
||||
payload: JSON.stringify(payload),
|
||||
},
|
||||
});
|
||||
notificationQueue.enqueue({ ...target, eventType, payload, logId: log.id });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const userTargets = await resolveUserNotificationTargets(eventType, payload);
|
||||
for (const target of userTargets) {
|
||||
const log = await prisma.notificationLog.create({
|
||||
@@ -157,6 +174,7 @@ eventBus.on(PAYMENT_STATUS_CHANGED, (payload) => dispatchNotification(PAYMENT_ST
|
||||
eventBus.on(AUTH_CODE_REQUESTED, (payload) => dispatchNotification(AUTH_CODE_REQUESTED, payload));
|
||||
eventBus.on("order:created:admin", (payload) => dispatchNotification("order:created:admin", payload));
|
||||
eventBus.on("review:created", (payload) => dispatchNotification("review:created", payload));
|
||||
eventBus.on(DELIVERY_FEE_ADJUSTED, (payload) => dispatchNotification(DELIVERY_FEE_ADJUSTED, payload));
|
||||
|
||||
async function shutdown() {
|
||||
notificationQueue.stop();
|
||||
|
||||
Reference in New Issue
Block a user