From c3b555189b097e7ce570ef6e0757de88be7331ba Mon Sep 17 00:00:00 2001 From: Knee Cola Date: Mon, 17 Nov 2025 13:30:47 +0100 Subject: [PATCH] Complete billedToTenant server action implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implemented full server-side persistence for the billedToTenant property: - Extract billedToTenant from formData in updateOrAddBill action - Add to MongoDB $set operations for updating existing bills - Include in new bill creation with value from form - Set default value (true) for bills added to subsequent months - Handle undefined values from existing database records using destructuring defaults This completes the feature - bills can now track whether they should be paid by the tenant, with backward compatibility for existing data. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/lib/actions/billActions.ts | 5 +++++ app/ui/BillEditForm.tsx | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/lib/actions/billActions.ts b/app/lib/actions/billActions.ts index 3a5de12..48155fc 100644 --- a/app/lib/actions/billActions.ts +++ b/app/lib/actions/billActions.ts @@ -145,6 +145,7 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI } = validatedFields.data; const billPaid = formData.get('billPaid') === 'on'; + const billedToTenant = formData.get('billedToTenant') === 'on'; const barcodeImage = formData.get('barcodeImage')?.valueOf() as string; // update the bill in the mongodb @@ -159,6 +160,7 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI const mongoDbSet = billAttachment ? { "bills.$[elem].name": billName, "bills.$[elem].paid": billPaid, + "bills.$[elem].billedToTenant": billedToTenant, "bills.$[elem].attachment": billAttachment, "bills.$[elem].notes": billNotes, "bills.$[elem].payedAmount": payedAmount, @@ -167,6 +169,7 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI }: { "bills.$[elem].name": billName, "bills.$[elem].paid": billPaid, + "bills.$[elem].billedToTenant": billedToTenant, "bills.$[elem].notes": billNotes, "bills.$[elem].payedAmount": payedAmount, "bills.$[elem].barcodeImage": barcodeImage, @@ -191,6 +194,7 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI _id: (new ObjectId()).toHexString(), name: billName, paid: billPaid, + billedToTenant: billedToTenant, attachment: billAttachment, notes: billNotes, payedAmount, @@ -254,6 +258,7 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI _id: (new ObjectId()).toHexString(), name: billName, paid: false, // New bills in subsequent months are unpaid + billedToTenant: true, // Default to true for subsequent months attachment: null, // No attachment for subsequent months notes: billNotes, payedAmount: null, diff --git a/app/ui/BillEditForm.tsx b/app/ui/BillEditForm.tsx index 09581d3..7586b66 100644 --- a/app/ui/BillEditForm.tsx +++ b/app/ui/BillEditForm.tsx @@ -29,7 +29,7 @@ export const BillEditForm:FC = ({ location, bill }) => { const t = useTranslations("bill-edit-form"); const locale = useLocale(); - const { _id: billID, name, paid, billedToTenant, attachment, notes, payedAmount: initialPayedAmount, barcodeImage: initialBarcodeImage } = bill ?? { _id:undefined, name:"", paid:false, billedToTenant:true, notes:"" }; + const { _id: billID, name, paid, billedToTenant = true, attachment, notes, payedAmount: initialPayedAmount, barcodeImage: initialBarcodeImage } = bill ?? { _id:undefined, name:"", paid:false, notes:"" }; const { yearMonth:{year: billYear, month: billMonth}, _id: locationID } = location;