refactor: improve notification naming and introduce type-safe enums
- Rename billFwd* to billsNotification* for clarity - Rename rentDueNotification* to rentNotification* for consistency - Rename utilBillsProofOfPayment to billsProofOfPayment - Introduce enums for type safety: - BillsNotificationStrategy (WhenPayed, WhenAttached) - BillsNotificationStatus (Scheduled, Sent, Failed) - RentNotificationStatus (Sent, Failed) - Replace "pending" status with "scheduled" for better semantics - Fix function names to proper camelCase - Fix incorrect import path in web-app/app/lib/format.ts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Db, ObjectId } from 'mongodb';
|
||||
import { BillingLocation, EmailStatus, UserSettings, generateShareId } from '@evidencija-rezija/shared-code';
|
||||
import { BillingLocation, BillsNotificationStatus, EmailStatus, RentNotificationStatus, UserSettings, generateShareId } from '@evidencija-rezija/shared-code';
|
||||
import { sendEmail } from './mailgunService';
|
||||
import { createLogger } from './logger';
|
||||
import { loadAndRender } from './emailTemplates';
|
||||
@@ -115,11 +115,11 @@ export async function sendRentDueNotifications(db: Db, budget: number): Promise<
|
||||
'yearMonth.year': currentYear,
|
||||
'yearMonth.month': currentMonth,
|
||||
'tenantEmailStatus': EmailStatus.Verified,
|
||||
'rentDueNotificationEnabled': true,
|
||||
'rentNotificationEnabled': true,
|
||||
'rentDueDay': currentDay,
|
||||
$or: [
|
||||
{ 'rentDueNotificationStatus': { $exists: false } },
|
||||
{ 'rentDueNotificationStatus': null }
|
||||
{ 'rentNotificationStatus': { $exists: false } },
|
||||
{ 'rentNotificationStatus': null }
|
||||
]
|
||||
})
|
||||
.toArray();
|
||||
@@ -170,10 +170,10 @@ export async function sendRentDueNotifications(db: Db, budget: number): Promise<
|
||||
});
|
||||
|
||||
// Update location status
|
||||
const newStatus = success ? 'sent' : 'failed';
|
||||
const newStatus = success ? RentNotificationStatus.Sent : RentNotificationStatus.Failed;
|
||||
await db.collection<BillingLocation>('lokacije').updateOne(
|
||||
{ _id: location._id },
|
||||
{ $set: { rentDueNotificationStatus: newStatus } }
|
||||
{ $set: { rentNotificationStatus: newStatus } }
|
||||
);
|
||||
|
||||
if (success) {
|
||||
@@ -213,8 +213,8 @@ export async function sendUtilityBillsNotifications(db: Db, budget: number): Pro
|
||||
'yearMonth.year': currentYear,
|
||||
'yearMonth.month': currentMonth,
|
||||
'tenantEmailStatus': EmailStatus.Verified,
|
||||
'billFwdEnabled': true,
|
||||
'billFwdStatus': 'pending'
|
||||
'billsNotificationEnabled': true,
|
||||
'billsNotificationStatus': BillsNotificationStatus.Scheduled
|
||||
})
|
||||
.toArray();
|
||||
|
||||
@@ -263,10 +263,10 @@ export async function sendUtilityBillsNotifications(db: Db, budget: number): Pro
|
||||
});
|
||||
|
||||
// Update location status
|
||||
const newStatus = success ? 'sent' : 'failed';
|
||||
const newStatus = success ? BillsNotificationStatus.Sent : BillsNotificationStatus.Failed;
|
||||
await db.collection<BillingLocation>('lokacije').updateOne(
|
||||
{ _id: location._id },
|
||||
{ $set: { billFwdStatus: newStatus } }
|
||||
{ $set: { billsNotificationStatus: newStatus } }
|
||||
);
|
||||
|
||||
if (success) {
|
||||
|
||||
Reference in New Issue
Block a user