Skip to content

Commit

Permalink
Fixed validations (#126)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: NIMENDRA <nimendradilshan11@gmail.com>
  • Loading branch information
lksnjw and nmdra authored Oct 14, 2024
1 parent 5d2794b commit 718365e
Show file tree
Hide file tree
Showing 22 changed files with 959 additions and 588 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ certs

docker-compose.caddy.yml

uploads
uploads

14 changes: 10 additions & 4 deletions backend/controllers/DLDeliveryController.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,19 @@ export const assignDriverToOrder = async () => {
driverID: driver._id,
drID: driver.driverID,
shopName: order.shopName,
shopEmail: order.shopEmail,
shopPhone: order.shopPhone,
pickupAddress:
`${order.shopAddress.houseNo || ''}, ${order.shopAddress.streetName || ''}, ${order.shopAddress.city || ''}, ${order.shopAddress.district || ''}`
.trim()
.replace(/^,|,$/g, ''),
customerName: order.customerName,
dropOffAddress:
`${order.customerAddress.streetAddress || ''}, ${order.customerAddress.city || ''}, ${order.customerAddress.zipCode || ''}, ${order.customerAddress.district || ''}`
.trim()
.replace(/^,|,$/g, ''),
customerEmail: order.customerEmail,
customerNumber: order.customerNumber,
dropOffAddress: order.customerAddress,
// `${order.customerAddress.streetAddress || ''}, ${order.customerAddress.city || ''}, ${order.customerAddress.zipCode || ''}, ${order.customerAddress.district || ''}`
// .trim()
// .replace(/^,|,$/g, ''),
})

await delivery.save()
Expand Down Expand Up @@ -112,8 +116,10 @@ export const sendEmailToDriver = async (driver, delivery) => {
<li><strong>Order ID:</strong> ${delivery.oID}</li>
<li><strong>Tracking ID:</strong> ${delivery.trackingID}</li>
<li><strong>Shop Name:</strong> ${delivery.shopName}</li>
<li><strong>Shop Contact:</strong> ${delivery.shopPhone}</li>
<li><strong>Pickup Address:</strong> ${delivery.pickupAddress}</li>
<li><strong>Customer Name:</strong> ${delivery.customerName}</li>
<li><strong>Customer Contact:</strong> ${delivery.customerNumber}</li>
<li><strong>Drop-Off Address:</strong> ${delivery.dropOffAddress}</li>
</ul>
Expand Down
28 changes: 19 additions & 9 deletions backend/controllers/DLOcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,22 +148,32 @@ const assignReadyOrders = async () => {
const customerName =
`${user.firstname || ''} ${user.lastname || ''}`.trim()

// Use the defaultAddress from the User model
const customerAddress = {
streetAddress: user.defaultAddress.streetAddress || 'N/A',
city: user.defaultAddress.city || 'N/A',
zipCode: user.defaultAddress.zipCode || 'N/A',
district: user.defaultAddress.district || 'N/A',
}
// console.log(`Customer Address: ${customerAddress.streetAddress}, ${customerAddress.city}`)
// // Use the defaultAddress from the User model
// const customerAddress = {
// streetAddress: user.defaultAddress.streetAddress || 'N/A',
// city: user.defaultAddress.city || 'N/A',
// zipCode: user.defaultAddress.zipCode || 'N/A',
// district: user.defaultAddress.district || 'N/A',
// }
// // console.log(`Customer Address: ${customerAddress.streetAddress}, ${customerAddress.city}`)

// Extract the shippingAddress fields from the user
const { name, address, city, phone, email } = order.shippingAddress

// Combine address and city into a single string
const cusAddress = `${address}, ${city}`

// Create a new dOrder with the customer and shop address and order data
const newDOrder = new dOrder({
oID: order._id.toString(), // Assigning the order ID from the Order model
orderID: generateOrderId(), // Randomly generated order ID
customerName: customerName, // Full name from User model
customerAddress: customerAddress, // Address from User model
customerEmail: email, // Email from User model
customerNumber: phone, // Phone number from User model
customerAddress: cusAddress, // Address from User model
shopName: shop.name, // Shop name from the Shop model
shopEmail: shop.email, // Shop email from the Shop model
shopPhone: shop.contactNumber, // Shop phone from the Shop model
shopAddress: {
houseNo: shop.address.houseNo, // House number from the Shop model
streetName: shop.address.streetName, // Street name from the Shop model
Expand Down
11 changes: 6 additions & 5 deletions backend/controllers/orderController.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ export const getTotalSales = async (req, res) => {
}
}


export const getShopTotalIncome = async (req, res) => {
try {
const totalIncome = await Order.aggregate([
Expand Down Expand Up @@ -290,11 +289,13 @@ export const getShopTotalIncome = async (req, res) => {
ownerName: '$farmerDetails.name', // Include the owner's name
},
},
]);
])

res.status(200).json(totalIncome); // Send the total income response
res.status(200).json(totalIncome) // Send the total income response
} catch (error) {
console.error('Error fetching shop total income with owner:', error);
res.status(500).json({ message: 'Error fetching total income for shops with owner' });
console.error('Error fetching shop total income with owner:', error)
res.status(500).json({
message: 'Error fetching total income for shops with owner',
})
}
}
22 changes: 22 additions & 0 deletions backend/models/DLDeliveryModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,35 @@ const DLDeliverySchema = new mongoose.Schema({
drID: {
type: String,
},

shopName: String,

shopEmail: {
type: String,
required: false,
},

shopPhone: {
type: String,
required: false,
},

pickupAddress: {
type: String,
},

customerName: String,

customerEmail: {
type: String,
required: false,
},

customerNumber: {
type: String,
required: false,
},

dropOffAddress: {
type: String,
},
Expand Down
30 changes: 26 additions & 4 deletions backend/models/DLOModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,23 @@ const dorderSchema = new mongoose.Schema(
type: String,
required: false,
},

customerEmail: {
type: String,
required: false,
},

customerNumber: {
type: String,
required: false,
},
customerAddress: {
streetAddress: { type: String, required: false },
city: { type: String, required: false },
zipCode: { type: String, required: false },
district: { type: String, required: false },
type: String,
required: false,
// streetAddress: { type: String, required: false },
// city: { type: String, required: false },
// zipCode: { type: String, required: false },
// district: { type: String, required: false },
},
shopName: {
type: String,
Expand All @@ -43,6 +55,16 @@ const dorderSchema = new mongoose.Schema(
required: [false, 'City is required'],
},
},
shopEmail: {
type: String,
required: false,
},

shopPhone: {
type: String,
required: false,
},

orderStatus: {
type: String,
enum: ['Pending', 'Ready', 'Picked Up', 'On The Way', 'Delivered'],
Expand Down
2 changes: 1 addition & 1 deletion backend/routes/orderRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ orderRouter.get('/get-user-orders/:id', getOrdersByUserId)
orderRouter.put('/:id', updateOrderStatus)
orderRouter.delete('/:id', DeleteOrder)
orderRouter.get('/get-shop/:id', getShopByFarmerId)
orderRouter.get('/shop-total-income', getShopTotalIncome);
orderRouter.get('/shop-total-income', getShopTotalIncome)

orderRouter.get('/:id', getOrderById) // Fetch order details by ID with populated farmer and user details

Expand Down
1 change: 1 addition & 0 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import commentRoutes from './routes/comments.js'
import newsRoutes from './routes/newsRoutes.js'

// Error handling

import { errorHandler, notFound } from './middlewares/errorMiddleware.js'

// Set up port from environment or default to 8000
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ const router = createBrowserRouter(
/>
<Route path="/coupens" element={<Coupens />} />
<Route path="/finance" element={<Finance />} />
<Route path="/manage-shop-income" element={<ManageShopIncome />} />
<Route
path="/manage-shop-income"
element={<ManageShopIncome />}
/>
</Route>

{/*
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Components/Admin/admnlogins.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const AdminLogin = ({ manager }) => {
<img
src={farmcartLogo} // Replace with the path to your logo image
alt="Logo"
className="h-16 w-auto mb-4 mx-auto"
className="h-10 w-auto mb-4 mx-auto"
/>
<div className="text-left mb-5">
<h2 className="text-3xl font-bold">Admin Login</h2>
Expand Down
19 changes: 0 additions & 19 deletions frontend/src/Components/Home/DHeader.jsx

This file was deleted.

31 changes: 31 additions & 0 deletions frontend/src/Components/delivery/DHeader.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react'

Check failure on line 1 in frontend/src/Components/delivery/DHeader.jsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontend/src/Components/delivery/DHeader.jsx#L1

[no-unused-vars] 'React' is defined but never used.
import { Link } from 'react-router-dom'
import logo from '../../assets/Logo.png'

const Header = () => {
return (
<div>
<div className="flex items-center justify-between py-6 mx-auto border-b max-w-7xl">
<div>
<Link to="/">
<img src={logo} alt="Logo" width={160} height={160} />
</Link>
</div>

<div className="flex items-center gap-4 text-sm">
<div className="flex items-center gap-4">
<h1>Welcome to FarmCart🌱 </h1>
<Link
to="/help"
className="text-black hover:text-[#99DD05] cursor-pointer hover:underline text-sm"
>
Help & Support
</Link>
</div>
</div>
</div>
</div>
)
}

export default Header
1 change: 0 additions & 1 deletion frontend/src/Layouts/BlogLayout.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Outlet } from 'react-router-dom'
// import Footer from '../Components/Home/Footer'
import Footer from '../Components/Home/FooterDashboard'
import DHeader from '../Components/Home/DHeader'
import BlogHeader from '../Components/Home/BlogHeader'

function BlogLayout() {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Layouts/DLayout.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Outlet } from 'react-router-dom'
// import Footer from '../Components/Home/Footer'
import Footer from '../Components/Home/FooterDashboard'
import DHeader from '../Components/Home/DHeader'
import DHeader from '../Components/delivery/DHeader'

function DLayout() {
return (
Expand Down
25 changes: 13 additions & 12 deletions frontend/src/Layouts/HelpLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ import HelpFooter from '../Components/Help/HelpFooter'
import HelpChatIcon from '../Components/Help/HelpChatIcon'

function HelpLayout() {

const user = JSON.parse(localStorage.getItem('user'))

// Handle the case where user is null or undefined
const customer = user ? {
id: user._id,
name: user.firstname,
email: user.email,
createdAt: Date.now(),
} : {
id: '01JA3JDNTD35GP144D83PPJVR6',
name: 'Guest',
email: 'guest@example.com',
createdAt: Date.now(),
}
const customer = user
? {
id: user._id,
name: user.firstname,
email: user.email,
createdAt: Date.now(),
}
: {
id: '01JA3JDNTD35GP144D83PPJVR6',
name: 'Guest',
email: 'guest@example.com',
createdAt: Date.now(),
}

return (
<div>
Expand Down
Loading

0 comments on commit 718365e

Please sign in to comment.