From 2ce04c4eb793a80f0dd9fe11132822c940e7b604 Mon Sep 17 00:00:00 2001 From: Aditya Valsangkar Date: Mon, 10 Aug 2026 23:59:32 +0530 Subject: [PATCH] updates --- backend/src/modules/expenses/expenses.controller.js | 12 ++++++++---- .../src/modules/notifications/notifications.model.js | 10 +++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/backend/src/modules/expenses/expenses.controller.js b/backend/src/modules/expenses/expenses.controller.js index efb7c1e..73f9850 100644 --- a/backend/src/modules/expenses/expenses.controller.js +++ b/backend/src/modules/expenses/expenses.controller.js @@ -103,7 +103,8 @@ export async function createExpense(req, res) { const note = await notificationsModel.create({ userId: firstApprover.id, title: "New expense pending your approval", - body: `${submitter.name || "An employee"} submitted a new expense for review.`, + body: `${submitter.name || "An employee"} submitted a ${category} expense for ${currency} ${amount}.`, + expenseId: expense.id, }); notifyUser(firstApprover.id, note.rows[0]); } @@ -214,14 +215,16 @@ export async function approveExpense(req, res) { const note = await notificationsModel.create({ userId: nextApprover.id, title: "Expense pending your approval", - body: `An expense from your queue needs review.`, + body: `${expense.category} expense for ${expense.currency} ${expense.amount} needs your review.`, + expenseId: expense.id, }); notifyUser(nextApprover.id, note.rows[0]); } else { const note = await notificationsModel.create({ userId: expense.user_id, title: "Expense approved", - body: `Your expense has been fully approved.`, + body: `Your ${expense.category} expense for ${expense.currency} ${expense.amount} has been fully approved.`, + expenseId: expense.id, }); notifyUser(expense.user_id, note.rows[0]); } @@ -295,7 +298,8 @@ export async function rejectExpense(req, res) { const note = await notificationsModel.create({ userId: expense.user_id, title: "Expense rejected", - body: `Your expense was rejected: ${String(comment).trim()}`, + body: `Your ${expense.category} expense for ${expense.currency} ${expense.amount} was rejected: ${String(comment).trim()}`, + expenseId: expense.id, }); notifyUser(expense.user_id, note.rows[0]); const updated = await expensesModel.getExpenseWithSteps(id); diff --git a/backend/src/modules/notifications/notifications.model.js b/backend/src/modules/notifications/notifications.model.js index b68bc7b..e356771 100644 --- a/backend/src/modules/notifications/notifications.model.js +++ b/backend/src/modules/notifications/notifications.model.js @@ -3,21 +3,21 @@ export const notificationsModel = { listByUser(userId) { return query( - "SELECT id, title, body, is_read, created_at FROM notifications WHERE user_id = $1 ORDER BY created_at DESC", + "SELECT id, title, body, is_read, expense_id, created_at FROM notifications WHERE user_id = $1 ORDER BY created_at DESC", [userId], ); }, - create({ userId, title, body }) { + create({ userId, title, body, expenseId = null }) { return query( - "INSERT INTO notifications (user_id, title, body) VALUES ($1, $2, $3) RETURNING id, title, body, is_read, created_at", - [userId, title, body], + "INSERT INTO notifications (user_id, title, body, expense_id) VALUES ($1, $2, $3, $4) RETURNING id, title, body, is_read, expense_id, created_at", + [userId, title, body, expenseId], ); }, markRead(id, userID) { return query( - "UPDATE notifications SET is_read = true WHERE id = $1 AND user_id = $2 RETURNING id, title, body, is_read, created_at", + "UPDATE notifications SET is_read = true WHERE id = $1 AND user_id = $2 RETURNING id, title, body, is_read, expense_id, created_at", [id, userID], ); },