implemented bill update
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Location } from '@/app/lib/db-types';
|
||||
import { PlainLocation, PlainBill, MongoLocation } from '@/app/lib/db-types';
|
||||
import clientPromise from '@/app/lib/mongodb';
|
||||
import { BillEditForm } from '@/app/ui/BillEditForm';
|
||||
import { ObjectId } from 'mongodb';
|
||||
@@ -9,9 +9,28 @@ const fetchBillById = async (locationID:string, billID:string) => {
|
||||
const db = client.db("rezije");
|
||||
|
||||
// find a location with the given locationID
|
||||
const billLocation = await db.collection<Location>("lokacije").findOne({ _id: locationID })
|
||||
const billLocation = await db.collection<MongoLocation>("lokacije").findOne({ _id: locationID })
|
||||
|
||||
if(!billLocation) {
|
||||
console.log(`Location ${locationID} not found`);
|
||||
return(null);
|
||||
}
|
||||
|
||||
// find a bill with the given billID
|
||||
return(billLocation?.bills.find(({ _id }) => _id.toString() === billID))
|
||||
const mongoBill = billLocation?.bills.find(({ _id }) => _id.toString() === billID);
|
||||
|
||||
if(!mongoBill) {
|
||||
console.log('Bill not found');
|
||||
return(null);
|
||||
}
|
||||
|
||||
const { _id, ...billBase } = mongoBill;
|
||||
|
||||
return({
|
||||
id: _id.toString(),
|
||||
...billBase
|
||||
} as PlainBill);
|
||||
|
||||
}
|
||||
|
||||
export default async function Page({ params:{ id } }: { params: { id:string } }) {
|
||||
@@ -21,7 +40,6 @@ export default async function Page({ params:{ id } }: { params: { id:string } })
|
||||
const bill = await fetchBillById(invoiceID, billID);
|
||||
|
||||
if (!bill) {
|
||||
console.log('Bill not found');
|
||||
notFound();
|
||||
}
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user