diff --git a/backend/controllers/couponController.js b/backend/controllers/couponController.js index 72da1fc6..cce33a4d 100644 --- a/backend/controllers/couponController.js +++ b/backend/controllers/couponController.js @@ -15,3 +15,15 @@ export const validCoupon = async (req, res) => { res.status(500).json({ message: error.message }) } } + +export const createCoupon = async (req, res) => { + try { + const { couponCode, discount, expiryDate } = req.body + + const coupon = await Coupon.create({ couponCode, discount, expiryDate }) + + res.status(201).json({ coupon }) + } catch (error) { + res.status(409).json({ message: error.message }) + } +} diff --git a/backend/controllers/orderController.js b/backend/controllers/orderController.js index 0b5aa9a3..513e90c4 100644 --- a/backend/controllers/orderController.js +++ b/backend/controllers/orderController.js @@ -67,8 +67,8 @@ export const getAllOrders = async (req, res) => { console.log('shopId', shopId) try { const orders = shopId - ? await Order.find({ 'farmer.shopId': shopId }) - : await Order.find() + ? await Order.find({ 'farmer.shopId': shopId }).sort({ _id: 1 }) + : await Order.find().sort({ _id: 1 }) res.status(200).json(orders) } catch (error) { diff --git a/backend/models/OrderModel.js b/backend/models/OrderModel.js index 00e5ada7..2cb7aec9 100644 --- a/backend/models/OrderModel.js +++ b/backend/models/OrderModel.js @@ -1,4 +1,5 @@ import mongoose from 'mongoose' +import { type } from 'os' const orderSchema = new mongoose.Schema({ farmer: { @@ -39,6 +40,18 @@ const orderSchema = new mongoose.Schema({ deliveryDate: { type: Date, }, + deliveredAt: { + type: Date, + default: null, + }, + deliverId: { + type: String, + default: null, + }, + deliverName: { + type: String, + default: null, + }, }) const Order = mongoose.model('Order', orderSchema) diff --git a/backend/routes/couponRouter.js b/backend/routes/couponRouter.js index 2a37865e..d88c941c 100644 --- a/backend/routes/couponRouter.js +++ b/backend/routes/couponRouter.js @@ -1,8 +1,9 @@ import express from 'express' -import { validCoupon } from '../controllers/couponController.js' +import { createCoupon, validCoupon } from '../controllers/couponController.js' const couponRouter = express.Router() couponRouter.post('/valid-coupon', validCoupon) +couponRouter.post('/create', createCoupon) export default couponRouter diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index be76e0c1..489c80ce 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -106,8 +106,6 @@ const router = createBrowserRouter( } /> } /> } /> - - } /> ) ) diff --git a/frontend/src/Pages/Customer/UserAllOrders.jsx b/frontend/src/Pages/Customer/UserAllOrders.jsx index 96a9c991..eda0d05d 100644 --- a/frontend/src/Pages/Customer/UserAllOrders.jsx +++ b/frontend/src/Pages/Customer/UserAllOrders.jsx @@ -1,6 +1,14 @@ import React, { useEffect, useMemo, useState } from 'react' import OrderTable from '../../Components/OrderTable' -import { Pagination, Table, TableBody, TableCell, TableColumn, TableHeader, TableRow } from '@nextui-org/react' +import { + Pagination, + Table, + TableBody, + TableCell, + TableColumn, + TableHeader, + TableRow, +} from '@nextui-org/react' function UserAllOrders() { const [page, setPage] = useState(1) @@ -132,14 +140,26 @@ function UserAllOrders() { {item.orderStatus} diff --git a/frontend/src/Pages/Shop/ShopList.jsx b/frontend/src/Pages/Shop/ShopList.jsx index 0624a4d0..5a4ba453 100644 --- a/frontend/src/Pages/Shop/ShopList.jsx +++ b/frontend/src/Pages/Shop/ShopList.jsx @@ -32,7 +32,6 @@ const ShopList = () => { fetchShops(); }, []); - // Fetch bug fix // Filtering and Sorting Logic const filteredShops = shops .filter((shop) => @@ -107,7 +106,6 @@ const ShopList = () => {

Special Promotion: 20% off on all products!

*/} - {/* Search Bar */} { className="border p-2 rounded w-full mb-4 focus:outline-none focus:ring-2 focus:ring-blue-500" /> - - {/* Loading Message */} {loading ? ( @@ -155,9 +151,6 @@ const ShopList = () => { ); - - - }; export default ShopList; diff --git a/frontend/src/Pages/Shop/ShopPage.jsx b/frontend/src/Pages/Shop/ShopPage.jsx index b76995b5..3fcf434c 100644 --- a/frontend/src/Pages/Shop/ShopPage.jsx +++ b/frontend/src/Pages/Shop/ShopPage.jsx @@ -26,10 +26,10 @@ const ShopPage = () => { setSearchTerm(e.target.value); }; - //Filter products based on search term + // Filter products based on search term const filteredProducts = shop.products?.filter(product => product.name.toLowerCase().includes(searchTerm.toLowerCase()) - ); + ); return ( diff --git a/frontend/src/Pages/farmer/FarmerDashboard.jsx b/frontend/src/Pages/farmer/FarmerDashboard.jsx index cbb9fb84..3942f11a 100644 --- a/frontend/src/Pages/farmer/FarmerDashboard.jsx +++ b/frontend/src/Pages/farmer/FarmerDashboard.jsx @@ -373,7 +373,19 @@ const Dashboard = () => { : item.orderStatus === 'Accept' ? 'bg-blue-500 p-1 rounded-md text-white ring-0' - : 'bg-red-500 p-1 rounded-md text-white ring-0' + : item.orderStatus === + 'Ready' + ? 'bg-purple-500 p-1 rounded-md text-white ring-0' + : item.orderStatus === + 'Pickup' + ? 'bg-orange-500 p-1 rounded-md text-white ring-0' + : item.orderStatus === + 'OnTheWay' + ? 'bg-indigo-500 p-1 rounded-md text-white ring-0' + : item.orderStatus === + 'Rejected' + ? 'bg-red-500 p-1 rounded-md text-white ring-0' + : 'bg-gray-500 p-1 rounded-md text-white ring-0' } value={item.orderStatus} onChange={(e) => @@ -386,6 +398,15 @@ const Dashboard = () => { + + + diff --git a/frontend/src/Pages/order/Cart.jsx b/frontend/src/Pages/order/Cart.jsx index 06559ef6..d2d309a9 100644 --- a/frontend/src/Pages/order/Cart.jsx +++ b/frontend/src/Pages/order/Cart.jsx @@ -2,7 +2,6 @@ import { useDisclosure } from '@nextui-org/react' import { useEffect, useState } from 'react' import { Link } from 'react-router-dom' // import CheckOutModal from './CheckOutModal' -// test // import { useGlobalRefetch } from '../Context/GlobalRefetch' import axios from 'axios' import toast from 'react-hot-toast' @@ -14,6 +13,7 @@ const Cart = () => { const [originalPrice, setOriginalPrice] = useState(0) // const { globalRefetch, setGlobalRefetch } = useGlobalReefetch() const [couponDiscount, setCouponDiscount] = useState(0) + const [disabledCouponButton, setDisabledCouponButton] = useState(false) useEffect(() => { const getCart = async () => { @@ -34,8 +34,6 @@ const Cart = () => { } // console.log('cart', cart) - //special handling for kg test - useEffect(() => { const calculateOriginalPrice = () => { const originalPrice = cart.reduce((acc, item) => { @@ -79,6 +77,7 @@ const Cart = () => { JSON.stringify((total * couponDiscount) / 100) ) toast.success('Coupon Applied Successfully') + setDisabledCouponButton(true) } } } catch (error) { @@ -313,9 +312,13 @@ const Cart = () => {