From b3e4e3591ce307252722da33f90259b01d9489d7 Mon Sep 17 00:00:00 2001 From: Knee Cola Date: Sun, 7 Dec 2025 16:05:42 +0100 Subject: [PATCH] (refactor) locationAction: optimizing query not to return binary data --- app/lib/actions/locationActions.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/lib/actions/locationActions.ts b/app/lib/actions/locationActions.ts index 9daa9d5..e3f47a1 100644 --- a/app/lib/actions/locationActions.ts +++ b/app/lib/actions/locationActions.ts @@ -420,6 +420,7 @@ export const fetchAllLocations = withUser(async (user:AuthenticatedUser, year:nu billedTo: "$$bill.billedTo", payedAmount: "$$bill.payedAmount", hasAttachment: { $ne: ["$$bill.attachment", null] }, + proofOfPayment: "$$bill.proofOfPayment", }, }, } @@ -435,7 +436,12 @@ export const fetchAllLocations = withUser(async (user:AuthenticatedUser, year:nu // "yearMonth": 1, "yearMonth.year": 1, "yearMonth.month": 1, - "bills": 1, + "bills._id": 1, + "bills.name": 1, + "bills.paid": 1, + "bills.hasAttachment": 1, + "bills.payedAmount": 1, + "bills.proofOfPayment.uploadedAt": 1, "seenByTenantAt": 1, // "bills.attachment": 0, // "bills.notes": 0, @@ -652,7 +658,7 @@ export const uploadUtilBillsProofOfPayment = async (locationID: string, formData } // Validate file type - if (file && file.type !== 'application/pdf') { + if (file && file.size > 0 && file.type !== 'application/pdf') { return { success: false, error: 'Only PDF files are accepted' }; }