optimized queries

This commit is contained in:
2025-08-11 12:19:29 +02:00
parent 3ce158825e
commit 44cdcf8cec

View File

@@ -238,7 +238,13 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI
.findOne({
_id: location._id,
"bills.name": billName
}, { projection: { "bills.$": 1 } });
}, {
projection: {
"bills.$": 1,
"bills.attachment": 0,
"bills.barcodeImage": 0
}
});
// Only add if bill with same name doesn't already exist
if (!existingBill) {
@@ -363,7 +369,12 @@ export const deleteBillById = withUser(async (user:AuthenticatedUser, locationID
if (deleteInSubsequentMonths) {
// Get the current location and bill to find the bill name and location name
const location = await dbClient.collection<BillingLocation>("lokacije")
.findOne({ _id: locationID, userId });
.findOne({ _id: locationID, userId }, {
projection: {
"bills.attachment.fileContentsBase64": 0,
"bills.barcodeImage": 0
}
});
if (location) {
const bill = location.bills.find(b => b._id === billID);