Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions backend/src/modules/expenses/expenses.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Comment on lines 105 to +107
});
notifyUser(firstApprover.id, note.rows[0]);
}
Expand Down Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions backend/src/modules/notifications/notifications.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Comment on lines +6 to +14
);
},

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],
);
},
Expand Down