implemented bill deletion + var rename

This commit is contained in:
2024-01-05 13:54:25 +01:00
parent 4ffe2de6ea
commit 86135199a9
12 changed files with 122 additions and 117 deletions

View File

@@ -1,31 +1,2 @@
import { PlainBill, MongoLocation } from '@/app/lib/db-types';
import clientPromise from '@/app/lib/mongodb';
export const fetchBillById = async (locationID:string, billID:string) => {
const client = await clientPromise;
const db = client.db("rezije");
// find a location with the given 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
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);
}
import { Bill, BillingLocation } from '@/app/lib/db-types';
import clientPromise from '@/app/lib/mongodb';