implementiran share by link
This commit is contained in:
@@ -207,8 +207,10 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI
|
||||
await gotoHome({ year: billYear, month: billMonth });
|
||||
}
|
||||
})
|
||||
/*
|
||||
Funkcija zamijenjena sa `fetchBillByUserAndId`, koja brže radi i ne treba korisnika
|
||||
|
||||
export const fetchBillById = withUser(async (user:AuthenticatedUser, locationID:string, billID:string, includeAttachmentBinary:boolean = false) => {
|
||||
export const fetchBillByUserAndId = withUser(async (user:AuthenticatedUser, locationID:string, billID:string, includeAttachmentBinary:boolean = false) => {
|
||||
|
||||
const { id: userId } = user;
|
||||
|
||||
@@ -245,6 +247,43 @@ export const fetchBillById = withUser(async (user:AuthenticatedUser, locationID:
|
||||
|
||||
return([billLocation, bill] as [BillingLocation, Bill]);
|
||||
})
|
||||
*/
|
||||
|
||||
export const fetchBillById = async (locationID:string, billID:string, includeAttachmentBinary:boolean = false) => {
|
||||
|
||||
|
||||
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,
|
||||
},
|
||||
{
|
||||
projection
|
||||
})
|
||||
|
||||
if(!billLocation) {
|
||||
console.log(`Location ${locationID} not found`);
|
||||
return(null);
|
||||
}
|
||||
|
||||
// find a bill with the given billID
|
||||
const bill = billLocation?.bills.find(({ _id }) => _id.toString() === billID);
|
||||
|
||||
if(!bill) {
|
||||
console.log('Bill not found');
|
||||
return(null);
|
||||
}
|
||||
|
||||
return([billLocation, bill] as [BillingLocation, Bill]);
|
||||
};
|
||||
|
||||
export const deleteBillById = withUser(async (user:AuthenticatedUser, locationID:string, billID:string, year:number, month:number) => {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user