implementiran share by link

This commit is contained in:
2024-12-13 17:50:12 +01:00
parent 439de9d305
commit 4ab61f9917
15 changed files with 312 additions and 15 deletions

View File

@@ -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) => {

View File

@@ -132,7 +132,10 @@ export const fetchAllLocations = withUser(async (user:AuthenticatedUser, year:nu
return(locations)
})
export const fetchLocationById = withUser(async (user:AuthenticatedUser, locationID:string) => {
/*
ova metoda je zamijenjena sa jednostavnijom `fetchLocationById`, koja brže radi jer ne provjerava korisnika
export const fetchLocationByUserAndId = withUser(async (user:AuthenticatedUser, locationID:string) => {
noStore();
@@ -158,7 +161,34 @@ export const fetchLocationById = withUser(async (user:AuthenticatedUser, locatio
}
return(billLocation);
})
});
*/
export const fetchLocationById = async (locationID:string) => {
noStore();
const dbClient = await getDbClient();
// find a location with the given locationID
const billLocation = await dbClient.collection<BillingLocation>("lokacije")
.findOne(
{ _id: locationID },
{
projection: {
// don't include the attachment binary data in the response
"bills.attachment.fileContentsBase64": 0,
},
}
);
if(!billLocation) {
console.log(`Location ${locationID} not found`);
return(null);
}
return(billLocation);
};
export const deleteLocationById = withUser(async (user:AuthenticatedUser, locationID:string, yearMonth:YearMonth) => {