diff --git a/backend/routes/order_route.ts b/backend/routes/order_route.ts index 0bd2a56..3ffba5e 100644 --- a/backend/routes/order_route.ts +++ b/backend/routes/order_route.ts @@ -4,6 +4,17 @@ import auth from "../middleware/auth"; import roles from "../middleware/roles"; const router = express.Router(); +router.get("/all", (req: Request, res: Response) => { + Order.find() + .then((orders: any) => { + res.send(orders); + }) + .catch((err: any) => { + console.error(err); + res.status(500).send({ error: "An error occurred fetching the orders." }); + }); +}); + // Route to fetch an order by its ID router.get("/:id", [auth, roles.volunteer], (req: Request, res: Response) => { Order.findById(req.params.id) diff --git a/frontend/src/app/reports/Dashboard.tsx b/frontend/src/app/reports/Dashboard.tsx index 8b29fa9..8bd29ee 100644 --- a/frontend/src/app/reports/Dashboard.tsx +++ b/frontend/src/app/reports/Dashboard.tsx @@ -141,6 +141,17 @@ export function makeOtherBrandsArray(orderData:any[]):string[] { } +export function filterBySuccessfulStatus(orderData:any[]):any[] { + + const filteredBySuccess: any[] = []; + orderData.forEach((order:any) => { + if (order.status == "successful"){ + filteredBySuccess.push(order); + } + }); + return filteredBySuccess; +} + @@ -439,6 +450,423 @@ export default function Dashboard() { ], "status": "successful" }, + // Add 12 more orders below: + { + "client": { + "_id": "65d91d857b2e523b16d35780", + "name": "Graceful Gabrielle", + "age": 31, + "region": "Flatonia", + "pets": [ + { + "isActive": true, + "animal": "cat", + "vet": true, + "food": "Petsmart", + "lbs": 6 + } + ] + }, + "createdOn": new Date("2021-03-10T12:00:00Z"), + "deliverBy": new Date("2021-03-10T12:00:00Z"), + "foodItems": [ + { + "brand": "Petsmart", + "weight": 6 + } + ], + "status": "failed" + }, + { + "client": { + "_id": "65d91d857b2e523b16d35781", + "name": "Harmonious Harper", + "age": 42, + "region": "Carmine", + "pets": [ + { + "isActive": true, + "animal": "large dog", + "vet": false, + "food": "Friskies", + "lbs": 10 + } + ] + }, + "createdOn": new Date("2021-05-05T12:00:00Z"), + "deliverBy": new Date("2021-05-05T12:00:00Z"), + "foodItems": [ + { + "brand": "Friskies", + "weight": 10 + } + ], + "status": "pending" + }, + { + "client": { + "_id": "65d91d857b2e523b16d35782", + "name": "Inventive Isaac", + "age": 35, + "region": "San Marcos Housing Authority", + "pets": [ + { + "isActive": true, + "animal": "cat", + "vet": true, + "food": "BirdFoods", + "lbs": 8 + } + ] + }, + "createdOn": new Date("2021-08-20T12:00:00Z"), + "deliverBy": new Date("2021-08-20T12:00:00Z"), + "foodItems": [ + { + "brand": "BirdFoods", + "weight": 8 + } + ], + "status": "successful" + }, + { + "client": { + "_id": "65d91d857b2e523b16d35783", + "name": "Joyful Jordan", + "age": 30, + "region": "San Marcos Senior Center", + "pets": [ + { + "isActive": true, + "animal": "small dog", + "vet": false, + "food": "Fiesta", + "lbs": 9 + } + ] + }, + "createdOn": new Date("2021-10-15T12:00:00Z"), + "deliverBy": new Date("2021-10-15T12:00:00Z"), + "foodItems": [ + { + "brand": "Fiesta", + "weight": 9 + } + ], + "status": "pending" + }, + { + "client": { + "_id": "65d91d857b2e523b16d35784", + "name": "Keen Kelly", + "age": 48, + "region": "Kyle", + "pets": [ + { + "isActive": true, + "animal": "large dog", + "vet": true, + "food": "Wholesomes", + "lbs": 16 + } + ] + }, + "createdOn": new Date("2022-01-05T12:00:00Z"), + "deliverBy": new Date("2022-01-05T12:00:00Z"), + "foodItems": [ + { + "brand": "Wholesomes", + "weight": 16 + } + ], + "status": "successful" + }, + { + "client": { + "_id": "65d91d857b2e523b16d35785", + "name": "Loyal Liam", + "age": 34, + "region": "La Vista", + "pets": [ + { + "isActive": true, + "animal": "small dog", + "vet": true, + "food": "Nutrena", + "lbs": 12 + } + ] + }, + "createdOn": new Date("2022-03-10T12:00:00Z"), + "deliverBy": new Date("2022-03-10T12:00:00Z"), + "foodItems": [ + { + "brand": "Nutrena", + "weight": 12 + } + ], + "status": "successful" + }, + { + "client": { + "_id": "65d91d857b2e523b16d35786", + "name": "Merry Melissa", + "age": 39, + "region": "Trinity Lutheran", + "pets": [ + { + "isActive": true, + "animal": "cat", + "vet": false, + "food": "Foodimals", + "lbs": 7 + } + ] + }, + "createdOn": new Date("2022-04-18T12:00:00Z"), + "deliverBy": new Date("2022-04-18T12:00:00Z"), + "foodItems": [ + { + "brand": "Foodimals", + "weight": 7 + } + ], + "status": "successful" + }, + { + "client": { + "_id": "65d91d857b2e523b16d35787", + "name": "Noble Nathan", + "age": 43, + "region": "Lockhart", + "pets": [ + { + "isActive": true, + "animal": "large dog", + "vet": true, + "food": "Fiesta", + "lbs": 22 + } + ] + }, + "createdOn": new Date("2022-06-05T12:00:00Z"), + "deliverBy": new Date("2022-06-05T12:00:00Z"), + "foodItems": [ + { + "brand": "Fiesta", + "weight": 22 + } + ], + "status": "successful" + }, + { + "client": { + "_id": "65d91d857b2e523b16d35788", + "name": "Optimistic Olivia", + "age": 26, + "region": "Prairie Lea", + "pets": [ + { + "isActive": true, + "animal": "cat", + "vet": true, + "food": "Petsmart", + "lbs": 6 + } + ] + }, + "createdOn": new Date("2022-08-20T12:00:00Z"), + "deliverBy": new Date("2022-08-20T12:00:00Z"), + "foodItems": [ + { + "brand": "Petsmart", + "weight": 6 + } + ], + "status": "pending" + }, + { + "client": { + "_id": "65d91d857b2e523b16d35789", + "name": "Patient Paul", + "age": 51, + "region": "La Vista", + "pets": [ + { + "isActive": true, + "animal": "small dog", + "vet": false, + "food": "HEB Texas Pets", + "lbs": 8 + } + ] + }, + "createdOn": new Date("2022-10-15T12:00:00Z"), + "deliverBy": new Date("2022-10-15T12:00:00Z"), + "foodItems": [ + { + "brand": "HEB Texas Pets", + "weight": 8 + } + ], + "status": "successful" + }, + { + "client": { + "_id": "65d91d857b2e523b16d3578a", + "name": "Quirky Quentin", + "age": 38, + "region": "Smithville", + "pets": [ + { + "isActive": true, + "animal": "cat", + "vet": true, + "food": "Wholesomes", + "lbs": 5 + } + ] + }, + "createdOn": new Date("2022-12-25T12:00:00Z"), + "deliverBy": new Date("2022-12-25T12:00:00Z"), + "foodItems": [ + { + "brand": "Wholesomes", + "weight": 5 + } + ], + "status": "successful" + }, + { + "client": { + "_id": "65d91d857b2e523b16d3578b", + "name": "Resilient Rachel", + "age": 44, + "region": "Giddings", + "pets": [ + { + "isActive": true, + "animal": "large dog", + "vet": true, + "food": "Nutrena", + "lbs": 18 + } + ] + }, + "createdOn": new Date("2023-02-10T12:00:00Z"), + "deliverBy": new Date("2023-02-10T12:00:00Z"), + "foodItems": [ + { + "brand": "Nutrena", + "weight": 18 + } + ], + "status": "failed" + }, + { + "client": { + "_id": "65d91d857b2e523b16d3578c", + "name": "Sincere Sarah", + "age": 29, + "region": "Bastrop", + "pets": [ + { + "isActive": true, + "animal": "small dog", + "vet": true, + "food": "HEB Texas Pets", + "lbs": 10 + } + ] + }, + "createdOn": new Date("2023-03-20T12:00:00Z"), + "deliverBy": new Date("2023-03-20T12:00:00Z"), + "foodItems": [ + { + "brand": "HEB Texas Pets", + "weight": 10 + } + ], + "status": "successful" + }, + { + "client": { + "_id": "65d91d857b2e523b16d3578d", + "name": "Tender Thomas", + "age": 46, + "region": "Luling", + "pets": [ + { + "isActive": true, + "animal": "cat", + "vet": false, + "food": "Friskies", + "lbs": 7 + } + ] + }, + "createdOn": new Date("2023-04-05T12:00:00Z"), + "deliverBy": new Date("2023-04-05T12:00:00Z"), + "foodItems": [ + { + "brand": "Friskies", + "weight": 7 + } + ], + "status": "pending" + }, + { + "client": { + "_id": "65d91d857b2e523b16d3578e", + "name": "Understanding Ursula", + "age": 33, + "region": "Wimberley", + "pets": [ + { + "isActive": true, + "animal": "large dog", + "vet": true, + "food": "Foodimals", + "lbs": 20 + } + ] + }, + "createdOn": new Date("2023-06-15T12:00:00Z"), + "deliverBy": new Date("2023-06-15T12:00:00Z"), + "foodItems": [ + { + "brand": "Foodimals", + "weight": 20 + } + ], + "status": "successful" + }, + { + "client": { + "_id": "65d91d857b2e523b16d3578f", + "name": "Valiant Victor", + "age": 47, + "region": "Elgin", + "pets": [ + { + "isActive": true, + "animal": "cat", + "vet": true, + "food": "Fiesta", + "lbs": 9 + } + ] + }, + "createdOn": new Date("2023-08-02T12:00:00Z"), + "deliverBy": new Date("2023-08-02T12:00:00Z"), + "foodItems": [ + { + "brand": "Fiesta", + "weight": 9 + } + ], + "status": "successful" + }, ]; @@ -580,9 +1008,12 @@ export default function Dashboard() { useEffect(() => { /*fetch(API_BASE_URL+'/order/all') .then(response => response.json()) - .then(orderData => setOrderData(orderData));// */ - setOrderData(FAKE_ORDER_DATA); - setDisplayedData(FAKE_ORDER_DATA); + .then(orderData => { + setOrderData(filterBySuccessfulStatus(orderData)); + setDisplayedData(filterBySuccessfulStatus(orderData)); + });// */ + setOrderData(filterBySuccessfulStatus(FAKE_ORDER_DATA)); + setDisplayedData(filterBySuccessfulStatus(FAKE_ORDER_DATA)); //setOtherBrands(makeOtherBrandsArray(FAKE_ORDER_DATA)); //co nsole.log(otherBrands); }, []); @@ -643,19 +1074,6 @@ export default function Dashboard() { return (
- {/* Search area */} -
- - -
))} -
{/* Table of orderData by brand*/} @@ -739,7 +1151,7 @@ export default function Dashboard() { {brands.map((brand, index) => ( {brand} - {totalLbs[index]} + {totalLbs[index] | 0} {/**/} ))} @@ -784,7 +1196,7 @@ export default function Dashboard() { {otherBrands.map((otherBrand, index) => ( {otherBrand} - {totalOtherLbs[index]} + {totalOtherLbs[index] | 0} {/**/} ))}