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,7 +2,7 @@
import { z } from 'zod';
import { getDbClient } from '../dbClient';
import { Bill, BilledTo, FileAttachment, BillingLocation } from '@evidencija-rezija/shared-code';
import { Bill, BilledTo, FileAttachment, BillingLocation, BillsNotificationStatus } from '@evidencija-rezija/shared-code';
import { ObjectId } from 'mongodb';
import { withUser } from '@/app/lib/auth';
import { AuthenticatedUser } from '../types/next-auth';
@@ -13,7 +13,7 @@ import { unstable_noStore, revalidatePath } from 'next/cache';
import { extractShareId, validateShareChecksum } from '@evidencija-rezija/shared-code';
import { validatePdfFile } from '../validators/pdfValidator';
import { checkUploadRateLimit } from '../uploadRateLimiter';
import { shouldUpdateBillFwdStatusWhenAttached, shouldUpdateBillFwdStatusWhenPayed } from '../billForwardingHelpers';
import { shouldUpdateBillsNotificationStatusWhenAttached, shouldUpdateBillsNotificationStatusWhenPayed } from '../billForwardingHelpers';
export type State = {
errors?: {
@@ -178,7 +178,7 @@ export const updateOrAddBill = withUser(async (user: AuthenticatedUser, location
const billAttachment = await serializeAttachment(attachmentFile);
// Fetch the location to check billFwdStatus conditions
// Fetch the location to check billsNotificationStatus conditions
const location = await dbClient.collection<BillingLocation>("lokacije").findOne({
_id: locationId,
userId
@@ -188,9 +188,9 @@ export const updateOrAddBill = withUser(async (user: AuthenticatedUser, location
return { success: false, error: 'Location not found' };
}
// Check if we should update billFwdStatus to "pending"
const shouldSetFwdPendingWhenAttached = shouldUpdateBillFwdStatusWhenAttached(location, billId, billAttachment !== null);
const shouldSetFwdPendingWhenPayed = shouldUpdateBillFwdStatusWhenPayed(location, billId, billPaid);
// Check if we should update billsNotificationStatus to `Scheduled`
const shouldSetFwdPendingWhenAttached = shouldUpdateBillsNotificationStatusWhenAttached(location, billId, billAttachment !== null);
const shouldSetFwdPendingWhenPayed = shouldUpdateBillsNotificationStatusWhenPayed(location, billId, billPaid);
const shouldSetFwdPending = shouldSetFwdPendingWhenAttached || shouldSetFwdPendingWhenPayed;
if (billId) {
@@ -215,9 +215,9 @@ export const updateOrAddBill = withUser(async (user: AuthenticatedUser, location
"bills.$[elem].hub3aText": hub3aText,
};
// Add billFwdStatus if needed
// Add billsNotificationStatus if needed
if (shouldSetFwdPending) {
(mongoDbSet as any).billFwdStatus = "pending";
(mongoDbSet as any).billsNotificationStatus = BillsNotificationStatus.Scheduled;
}
// update bill in given location with the given locationID
@@ -253,10 +253,10 @@ export const updateOrAddBill = withUser(async (user: AuthenticatedUser, location
}
};
// Add billFwdStatus update if needed
// Add billsNotificationStatus update if needed
if (shouldSetFwdPending) {
updateOp.$set = {
billFwdStatus: "pending"
billsNotificationStatus: BillsNotificationStatus.Scheduled
};
}