(refactor) locationAction: optimizing query not to return binary data

This commit is contained in:
Knee Cola
2025-12-07 16:05:42 +01:00
parent 47bea328e7
commit b3e4e3591c

View File

@@ -420,6 +420,7 @@ export const fetchAllLocations = withUser(async (user:AuthenticatedUser, year:nu
billedTo: "$$bill.billedTo", billedTo: "$$bill.billedTo",
payedAmount: "$$bill.payedAmount", payedAmount: "$$bill.payedAmount",
hasAttachment: { $ne: ["$$bill.attachment", null] }, hasAttachment: { $ne: ["$$bill.attachment", null] },
proofOfPayment: "$$bill.proofOfPayment",
}, },
}, },
} }
@@ -435,7 +436,12 @@ export const fetchAllLocations = withUser(async (user:AuthenticatedUser, year:nu
// "yearMonth": 1, // "yearMonth": 1,
"yearMonth.year": 1, "yearMonth.year": 1,
"yearMonth.month": 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, "seenByTenantAt": 1,
// "bills.attachment": 0, // "bills.attachment": 0,
// "bills.notes": 0, // "bills.notes": 0,
@@ -652,7 +658,7 @@ export const uploadUtilBillsProofOfPayment = async (locationID: string, formData
} }
// Validate file type // 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' }; return { success: false, error: 'Only PDF files are accepted' };
} }