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) => {
|
||||
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
|
||||
@@ -5,6 +5,23 @@ import { Session } from 'next-auth';
|
||||
import { AuthenticatedUser } from './types/next-auth';
|
||||
import { defaultLocale } from '../i18n';
|
||||
|
||||
export const myAuth = () => {
|
||||
|
||||
// Ovo koristim u developmentu
|
||||
//
|
||||
// const session:Session = {
|
||||
// user: {
|
||||
// id: "123",
|
||||
// name: "Test User",
|
||||
// },
|
||||
// expires: "123",
|
||||
// };
|
||||
//
|
||||
// return(Promise.resolve(session));
|
||||
|
||||
return(auth());
|
||||
}
|
||||
|
||||
export const authConfig: NextAuthConfig = {
|
||||
callbacks: {
|
||||
// method verifies if the user is logged in or not
|
||||
@@ -83,7 +100,7 @@ export const isAuthErrorMessage = (obj: any): obj is AuthErrorMessage => {
|
||||
}
|
||||
|
||||
export const withUser = <T, A extends any[]>(fn: (user: AuthenticatedUser, ...args:A) => Promise<T>) => async (...args:A) => {
|
||||
const session = await auth();
|
||||
const session = await myAuth();
|
||||
|
||||
if(!session) {
|
||||
throw new Error("Not authenticated")
|
||||
|
||||
Reference in New Issue
Block a user