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:
@@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { z } from 'zod';
|
||||
import { getDbClient } from '../dbClient';
|
||||
import { BillingLocation, FileAttachment, YearMonth, EmailStatus } from '@evidencija-rezija/shared-code';
|
||||
import { BillingLocation, FileAttachment, YearMonth, EmailStatus, BillsNotificationStrategy } from '@evidencija-rezija/shared-code';
|
||||
import { ObjectId } from 'mongodb';
|
||||
import { withUser } from '@/app/lib/auth';
|
||||
import { AuthenticatedUser } from '../types/next-auth';
|
||||
@@ -20,11 +20,11 @@ export type State = {
|
||||
tenantName?: string[];
|
||||
tenantStreet?: string[];
|
||||
tenantTown?: string[];
|
||||
billFwdEnabled?: string[];
|
||||
billsNotificationEnabled?: string[];
|
||||
tenantEmail?: string[];
|
||||
tenantEmailStatus?: string[];
|
||||
billFwdStrategy?: string[];
|
||||
rentDueNotificationEnabled?: string[];
|
||||
billsNotificationStrategy?: string[];
|
||||
rentNotificationEnabled?: string[];
|
||||
rentDueDay?: string[];
|
||||
rentAmount?: string[];
|
||||
updateScope?: string[];
|
||||
@@ -44,12 +44,12 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
|
||||
tenantName: z.string().max(30).optional().nullable(),
|
||||
tenantStreet: z.string().max(27).optional().nullable(),
|
||||
tenantTown: z.string().max(27).optional().nullable(),
|
||||
billFwdEnabled: z.boolean().optional().nullable(),
|
||||
billsNotificationEnabled: z.boolean().optional().nullable(),
|
||||
tenantEmail: z.string().email(t("tenant-email-invalid")).optional().or(z.literal("")).nullable(),
|
||||
tenantEmailStatus: z.enum([EmailStatus.Unverified, EmailStatus.VerificationPending, EmailStatus.Verified, EmailStatus.Unsubscribed]).optional().nullable(),
|
||||
tenantEmailLanguage: z.enum(["hr", "en"]).optional().nullable(),
|
||||
billFwdStrategy: z.enum(["when-payed", "when-attached"]).optional().nullable(),
|
||||
rentDueNotificationEnabled: z.boolean().optional().nullable(),
|
||||
billsNotificationStrategy: z.enum([BillsNotificationStrategy.WhenPayed, BillsNotificationStrategy.WhenAttached]).optional().nullable(),
|
||||
rentNotificationEnabled: z.boolean().optional().nullable(),
|
||||
rentDueDay: z.coerce.number().min(1).max(31).optional().nullable(),
|
||||
rentAmount: z.coerce.number().int(t("rent-amount-integer")).positive(t("rent-amount-positive")).optional().nullable(),
|
||||
addToSubsequentMonths: z.boolean().optional().nullable(),
|
||||
@@ -86,7 +86,7 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
|
||||
path: ["tenantTown"],
|
||||
})
|
||||
.refine((data) => {
|
||||
if (data.billFwdEnabled || data.rentDueNotificationEnabled) {
|
||||
if (data.billsNotificationEnabled || data.rentNotificationEnabled) {
|
||||
return !!data.tenantEmail && data.tenantEmail.trim().length > 0;
|
||||
}
|
||||
return true;
|
||||
@@ -95,7 +95,7 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
|
||||
path: ["tenantEmail"],
|
||||
})
|
||||
.refine((data) => {
|
||||
if (data.rentDueNotificationEnabled) {
|
||||
if (data.rentNotificationEnabled) {
|
||||
return !!data.rentAmount && data.rentAmount > 0;
|
||||
}
|
||||
return true;
|
||||
@@ -134,12 +134,12 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
|
||||
tenantName: formData.get('tenantName') || null,
|
||||
tenantStreet: formData.get('tenantStreet') || null,
|
||||
tenantTown: formData.get('tenantTown') || null,
|
||||
billFwdEnabled: formData.get('billFwdEnabled') === 'on',
|
||||
billsNotificationEnabled: formData.get('billsNotificationEnabled') === 'on',
|
||||
tenantEmail: formData.get('tenantEmail') || null,
|
||||
tenantEmailStatus: formData.get('tenantEmailStatus') as "unverified" | "verification-pending" | "verified" | "unsubscribed" | undefined,
|
||||
tenantEmailLanguage: formData.get('tenantEmailLanguage') as "hr" | "en" | undefined,
|
||||
billFwdStrategy: formData.get('billFwdStrategy') as "when-payed" | "when-attached" | undefined,
|
||||
rentDueNotificationEnabled: formData.get('rentDueNotificationEnabled') === 'on',
|
||||
billsNotificationStrategy: formData.get('billsNotificationStrategy') as BillsNotificationStrategy | undefined,
|
||||
rentNotificationEnabled: formData.get('rentNotificationEnabled') === 'on',
|
||||
rentDueDay: formData.get('rentDueDay') || null,
|
||||
rentAmount: formData.get('rentAmount') || null,
|
||||
addToSubsequentMonths: formData.get('addToSubsequentMonths') === 'on',
|
||||
@@ -161,12 +161,12 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
|
||||
tenantName,
|
||||
tenantStreet,
|
||||
tenantTown,
|
||||
billFwdEnabled,
|
||||
billsNotificationEnabled,
|
||||
tenantEmail,
|
||||
tenantEmailStatus,
|
||||
tenantEmailLanguage,
|
||||
billFwdStrategy,
|
||||
rentDueNotificationEnabled,
|
||||
billsNotificationStrategy,
|
||||
rentNotificationEnabled,
|
||||
rentDueDay,
|
||||
rentAmount,
|
||||
addToSubsequentMonths,
|
||||
@@ -220,12 +220,12 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
|
||||
tenantName: tenantName || null,
|
||||
tenantStreet: tenantStreet || null,
|
||||
tenantTown: tenantTown || null,
|
||||
billFwdEnabled: billFwdEnabled || false,
|
||||
billsNotificationEnabled: billsNotificationEnabled || false,
|
||||
tenantEmail: tenantEmail || null,
|
||||
tenantEmailStatus: finalEmailStatus,
|
||||
tenantEmailLanguage: tenantEmailLanguage || null,
|
||||
billFwdStrategy: billFwdStrategy || "when-payed",
|
||||
rentDueNotificationEnabled: rentDueNotificationEnabled || false,
|
||||
billsNotificationStrategy: billsNotificationStrategy || BillsNotificationStrategy.WhenPayed,
|
||||
rentNotificationEnabled: rentNotificationEnabled || false,
|
||||
rentDueDay: rentDueDay || null,
|
||||
rentAmount: rentAmount || null,
|
||||
}
|
||||
@@ -253,12 +253,12 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
|
||||
tenantName: tenantName || null,
|
||||
tenantStreet: tenantStreet || null,
|
||||
tenantTown: tenantTown || null,
|
||||
billFwdEnabled: billFwdEnabled || false,
|
||||
billsNotificationEnabled: billsNotificationEnabled || false,
|
||||
tenantEmail: tenantEmail || null,
|
||||
tenantEmailStatus: finalEmailStatus,
|
||||
tenantEmailLanguage: tenantEmailLanguage || null,
|
||||
billFwdStrategy: billFwdStrategy || "when-payed",
|
||||
rentDueNotificationEnabled: rentDueNotificationEnabled || false,
|
||||
billsNotificationStrategy: billsNotificationStrategy || BillsNotificationStrategy.WhenPayed,
|
||||
rentNotificationEnabled: rentNotificationEnabled || false,
|
||||
rentDueDay: rentDueDay || null,
|
||||
rentAmount: rentAmount || null,
|
||||
}
|
||||
@@ -279,12 +279,12 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
|
||||
tenantName: tenantName || null,
|
||||
tenantStreet: tenantStreet || null,
|
||||
tenantTown: tenantTown || null,
|
||||
billFwdEnabled: billFwdEnabled || false,
|
||||
billsNotificationEnabled: billsNotificationEnabled || false,
|
||||
tenantEmail: tenantEmail || null,
|
||||
tenantEmailStatus: finalEmailStatus,
|
||||
tenantEmailLanguage: tenantEmailLanguage || null,
|
||||
billFwdStrategy: billFwdStrategy || "when-payed",
|
||||
rentDueNotificationEnabled: rentDueNotificationEnabled || false,
|
||||
billsNotificationStrategy: billsNotificationStrategy || BillsNotificationStrategy.WhenPayed,
|
||||
rentNotificationEnabled: rentNotificationEnabled || false,
|
||||
rentDueDay: rentDueDay || null,
|
||||
rentAmount: rentAmount || null,
|
||||
}
|
||||
@@ -304,12 +304,12 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
|
||||
tenantName: tenantName || null,
|
||||
tenantStreet: tenantStreet || null,
|
||||
tenantTown: tenantTown || null,
|
||||
billFwdEnabled: billFwdEnabled || false,
|
||||
billsNotificationEnabled: billsNotificationEnabled || false,
|
||||
tenantEmail: tenantEmail || null,
|
||||
tenantEmailStatus: tenantEmailStatus as EmailStatus || EmailStatus.Unverified,
|
||||
tenantEmailLanguage: tenantEmailLanguage || null,
|
||||
billFwdStrategy: billFwdStrategy || "when-payed",
|
||||
rentDueNotificationEnabled: rentDueNotificationEnabled || false,
|
||||
billsNotificationStrategy: billsNotificationStrategy || BillsNotificationStrategy.WhenPayed,
|
||||
rentNotificationEnabled: rentNotificationEnabled || false,
|
||||
rentDueDay: rentDueDay || null,
|
||||
rentAmount: rentAmount || null,
|
||||
yearMonth: yearMonth,
|
||||
@@ -381,12 +381,12 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
|
||||
tenantName: tenantName || null,
|
||||
tenantStreet: tenantStreet || null,
|
||||
tenantTown: tenantTown || null,
|
||||
billFwdEnabled: billFwdEnabled || false,
|
||||
billsNotificationEnabled: billsNotificationEnabled || false,
|
||||
tenantEmail: tenantEmail || null,
|
||||
tenantEmailStatus: tenantEmailStatus as EmailStatus || EmailStatus.Unverified,
|
||||
tenantEmailLanguage: tenantEmailLanguage || null,
|
||||
billFwdStrategy: billFwdStrategy || "when-payed",
|
||||
rentDueNotificationEnabled: rentDueNotificationEnabled || false,
|
||||
billsNotificationStrategy: billsNotificationStrategy || BillsNotificationStrategy.WhenPayed,
|
||||
rentNotificationEnabled: rentNotificationEnabled || false,
|
||||
rentDueDay: rentDueDay || null,
|
||||
rentAmount: rentAmount || null,
|
||||
yearMonth: { year: monthData.year, month: monthData.month },
|
||||
@@ -495,8 +495,8 @@ export const fetchAllLocations = withUser(async (user:AuthenticatedUser, year:nu
|
||||
// "bills.hub3aText": 1,
|
||||
// project only file name - leave out file content so that
|
||||
// less data is transferred to the client
|
||||
"utilBillsProofOfPayment.fileName": 1,
|
||||
"utilBillsProofOfPayment.uploadedAt": 1,
|
||||
"billsProofOfPayment.fileName": 1,
|
||||
"billsProofOfPayment.uploadedAt": 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -558,7 +558,7 @@ export const fetchLocationById = async (locationID:string) => {
|
||||
projection: {
|
||||
// don't include the attachment binary data in the response
|
||||
"bills.attachment.fileContentsBase64": 0,
|
||||
"utilBillsProofOfPayment.fileContentsBase64": 0,
|
||||
"billsProofOfPayment.fileContentsBase64": 0,
|
||||
},
|
||||
}
|
||||
);
|
||||
@@ -691,7 +691,7 @@ const serializeAttachment = async (file: File | null):Promise<FileAttachment | n
|
||||
* @param ipAddress - Optional IP address for rate limiting
|
||||
* @returns Promise with success status
|
||||
*/
|
||||
export const uploadUtilBillsProofOfPayment = async (
|
||||
export const uploadBillsProofOfPayment = async (
|
||||
shareId: string,
|
||||
formData: FormData,
|
||||
ipAddress?: string
|
||||
@@ -729,7 +729,7 @@ export const uploadUtilBillsProofOfPayment = async (
|
||||
const dbClient = await getDbClient();
|
||||
|
||||
const location = await dbClient.collection<BillingLocation>("lokacije")
|
||||
.findOne({ _id: locationID }, { projection: { userId: 1, utilBillsProofOfPayment: 1, shareTTL: 1 } });
|
||||
.findOne({ _id: locationID }, { projection: { userId: 1, billsProofOfPayment: 1, shareTTL: 1 } });
|
||||
|
||||
if (!location || !location.userId) {
|
||||
return { success: false, error: 'Invalid request' };
|
||||
@@ -741,12 +741,12 @@ export const uploadUtilBillsProofOfPayment = async (
|
||||
}
|
||||
|
||||
// Check if proof of payment already uploaded
|
||||
if (location.utilBillsProofOfPayment) {
|
||||
if (location.billsProofOfPayment) {
|
||||
return { success: false, error: 'Proof of payment already uploaded for this location' };
|
||||
}
|
||||
|
||||
// 4. FILE VALIDATION
|
||||
const file = formData.get('utilBillsProofOfPayment') as File;
|
||||
const file = formData.get('billsProofOfPayment') as File;
|
||||
|
||||
if (!file || file.size === 0) {
|
||||
return { success: false, error: 'No file provided' };
|
||||
@@ -770,7 +770,7 @@ export const uploadUtilBillsProofOfPayment = async (
|
||||
.updateOne(
|
||||
{ _id: locationID },
|
||||
{ $set: {
|
||||
utilBillsProofOfPayment: attachment
|
||||
billsProofOfPayment: attachment
|
||||
} }
|
||||
);
|
||||
|
||||
@@ -786,7 +786,7 @@ export const uploadUtilBillsProofOfPayment = async (
|
||||
|
||||
/**
|
||||
* Upload rent proof of payment (for tenants via share link)
|
||||
* Similar to uploadUtilBillsProofOfPayment but for rent payments
|
||||
* Similar to uploadBillsProofOfPayment but for rent payments
|
||||
*/
|
||||
export const uploadRentProofOfPayment = async (
|
||||
shareId: string,
|
||||
|
||||
@@ -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 } }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { BillingLocation, BilledTo } from '@evidencija-rezija/shared-code';
|
||||
import { BillingLocation, BilledTo, BillsNotificationStatus, BillsNotificationStrategy } from '@evidencija-rezija/shared-code';
|
||||
|
||||
/**
|
||||
* Checks if billFwdStatus should be updated to "pending" based on attachment status
|
||||
* Checks if billsNotificationStatus should be updated to `Scheduled` based on attachment status
|
||||
* @param location - The billing location containing the bill
|
||||
* @param currentBillId - The ID of the bill being updated (to exclude from check)
|
||||
* @param hasNewAttachment - Whether a new attachment is being added to the current bill
|
||||
* @returns true if billFwdStatus should be set to "pending"
|
||||
* @returns true if billsNotificationStatus should be set to `Scheduled`
|
||||
*/
|
||||
export const shouldUpdateBillFwdStatusWhenAttached = (
|
||||
export const shouldUpdateBillsNotificationStatusWhenAttached = (
|
||||
location: BillingLocation,
|
||||
currentBillId: string | undefined,
|
||||
hasNewAttachment: boolean
|
||||
@@ -17,18 +17,18 @@ export const shouldUpdateBillFwdStatusWhenAttached = (
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check billFwdEnabled is true
|
||||
if (location.billFwdEnabled !== true) {
|
||||
// Check billsNotificationEnabled is true
|
||||
if (location.billsNotificationEnabled !== true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check billFwdStrategy is "when-attached"
|
||||
if (location.billFwdStrategy !== "when-attached") {
|
||||
// Check billsNotificationStrategy is `WhenAttached`
|
||||
if (location.billsNotificationStrategy !== BillsNotificationStrategy.WhenAttached) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check bills have already been sent or are pending -> don't sent them again
|
||||
if (location.billFwdStatus === "pending" || location.billFwdStatus === "sent") {
|
||||
// Check bills have already been sent or are scheduled -> don't send them again
|
||||
if (location.billsNotificationStatus === BillsNotificationStatus.Scheduled || location.billsNotificationStatus === BillsNotificationStatus.Sent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -49,13 +49,13 @@ export const shouldUpdateBillFwdStatusWhenAttached = (
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if billFwdStatus should be updated to "pending" based on paid status
|
||||
* Checks if billsNotificationStatus should be updated to "scheduled" based on paid status
|
||||
* @param location - The billing location containing the bill
|
||||
* @param currentBillId - The ID of the bill being updated (to exclude from check)
|
||||
* @param isPaid - Whether the current bill is being marked as paid
|
||||
* @returns true if billFwdStatus should be set to "pending"
|
||||
* @returns true if billsNotificationStatus should be set to "scheduled"
|
||||
*/
|
||||
export const shouldUpdateBillFwdStatusWhenPayed = (
|
||||
export const shouldUpdateBillsNotificationStatusWhenPayed = (
|
||||
location: BillingLocation,
|
||||
currentBillId: string | undefined,
|
||||
isPaid: boolean
|
||||
@@ -65,18 +65,18 @@ export const shouldUpdateBillFwdStatusWhenPayed = (
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check billFwdEnabled is true
|
||||
if (location.billFwdEnabled !== true) {
|
||||
// Check billsNotificationEnabled is true
|
||||
if (location.billsNotificationEnabled !== true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check billFwdStrategy is "when-payed"
|
||||
if (location.billFwdStrategy !== "when-payed") {
|
||||
// Check billsNotificationStrategy is `WhenPayed`
|
||||
if (location.billsNotificationStrategy !== BillsNotificationStrategy.WhenPayed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check bills have already been sent or are pending -> don't sent them again
|
||||
if (location.billFwdStatus === "pending" || location.billFwdStatus === "sent") {
|
||||
// Check bills have already been sent or are scheduled -> don't sent them again
|
||||
if (location.billsNotificationStatus === BillsNotificationStatus.Scheduled || location.billsNotificationStatus === BillsNotificationStatus.Sent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { YearMonth } from "./db-types";
|
||||
import { YearMonth } from "@evidencija-rezija/shared-code";
|
||||
|
||||
export const formatYearMonth = ({ year, month }: YearMonth): string => {
|
||||
return `${year}-${month<10?"0":""}${month}`;
|
||||
|
||||
Reference in New Issue
Block a user