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:
Knee Cola
2026-01-06 13:05:22 +01:00
parent 0556ad2533
commit fb35e0278e
13 changed files with 160 additions and 137 deletions

View File

@@ -2,13 +2,13 @@
import { getDbClient } from '../dbClient';
import { ObjectId } from 'mongodb';
import { Bill, BillingLocation, YearMonth } from '@evidencija-rezija/shared-code';
import { Bill, BillingLocation, BillsNotificationStatus, YearMonth } from '@evidencija-rezija/shared-code';
import { AuthenticatedUser } from '../types/next-auth';
import { withUser } from '../auth';
import { unstable_noStore as noStore, unstable_noStore, revalidatePath } from 'next/cache';
import { getLocale } from 'next-intl/server';
import { gotoHomeWithMessage } from './navigationActions';
import { shouldUpdateBillFwdStatusWhenPayed } from '../billForwardingHelpers';
import { shouldUpdateBillsNotificationStatusWhenPayed } from '../billForwardingHelpers';
/**
* Server-side action which adds a new month to the database
@@ -44,7 +44,7 @@ export const addMonth = withUser(async (user:AuthenticatedUser, { year, month }:
...prevLocation,
// clear properties specific to the month
seenByTenantAt: undefined,
utilBillsProofOfPayment: undefined,
billsProofOfPayment: undefined,
// assign a new ID
_id: (new ObjectId()).toHexString(),
yearMonth: {
@@ -234,11 +234,11 @@ export const updateMonth = withUser(async (
// Check if any paid bill triggers forwarding (only need to check once)
const firstPaidUpdate = locationUpdates.find(update => update.paid === true);
if (firstPaidUpdate && shouldUpdateBillFwdStatusWhenPayed(location, firstPaidUpdate.billId, true)) {
// Update billFwdStatus to "pending"
if (firstPaidUpdate && shouldUpdateBillsNotificationStatusWhenPayed(location, firstPaidUpdate.billId, true)) {
// Update billsNotificationStatus to "scheduled"
await dbClient.collection<BillingLocation>("lokacije").updateOne(
{ _id: locationId },
{ $set: { billFwdStatus: "pending" } }
{ $set: { billsNotificationStatus: BillsNotificationStatus.Scheduled } }
);
}
}