optimization: not fetching binary data if not needed
This commit is contained in:
@@ -196,14 +196,27 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI
|
||||
}
|
||||
})
|
||||
|
||||
export const fetchBillById = withUser(async (user:AuthenticatedUser, locationID:string, billID:string) => {
|
||||
export const fetchBillById = withUser(async (user:AuthenticatedUser, locationID:string, billID:string, includeAttachmentBinary:boolean = false) => {
|
||||
|
||||
const { id: userId } = user;
|
||||
|
||||
const dbClient = await getDbClient();
|
||||
|
||||
// don't include the attachment binary data in the response
|
||||
// if the attachment binary data is not needed
|
||||
const projection = includeAttachmentBinary ? {} : {
|
||||
"bills.attachment.fileContentsBase64": 0,
|
||||
};
|
||||
|
||||
// find a location with the given locationID
|
||||
const billLocation = await dbClient.collection<BillingLocation>("lokacije").findOne({ _id: locationID, userId })
|
||||
const billLocation = await dbClient.collection<BillingLocation>("lokacije").findOne(
|
||||
{
|
||||
_id: locationID,
|
||||
userId
|
||||
},
|
||||
{
|
||||
projection
|
||||
})
|
||||
|
||||
if(!billLocation) {
|
||||
console.log(`Location ${locationID} not found`);
|
||||
|
||||
Reference in New Issue
Block a user