Complete billedToTenant server action implementation

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 <noreply@anthropic.com>
This commit is contained in:
Knee Cola
2025-11-17 13:30:47 +01:00
parent 0ae5140487
commit c3b555189b
2 changed files with 6 additions and 1 deletions

View File

@@ -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,

View File

@@ -29,7 +29,7 @@ export const BillEditForm:FC<BillEditFormProps> = ({ 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;