-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import orderModel from "../models/orderModel.js"; | ||
import userModel from "../models/userModel"; | ||
|
||
// Placing orders using COD Method | ||
const placeOrder = async (req, res) => { | ||
try { | ||
const { userId, items, amount, address } = req.body; | ||
|
||
const orderData = { | ||
userId, | ||
items, | ||
address, | ||
amount, | ||
paymentMethod: "COD", | ||
payment: false, | ||
date: Date.now(), | ||
}; | ||
|
||
const newOrder = new orderModel(orderData); | ||
await newOrder.save(); | ||
|
||
await userModel.findByIdAndUpdate(userId, { cartData: {} }); | ||
|
||
res.json({ success: true, message: "Order Placed" }); | ||
} catch (error) { | ||
console.log(error); | ||
res.json({ success: false, message: error.message }); | ||
} | ||
}; | ||
|
||
// Placing orders using Stripe Method | ||
const placeOrderStripe = async (req, res) => {}; | ||
|
||
// All Orders data for Admin Panel | ||
const allOrders = async (req, res) => {}; | ||
|
||
// User Order Data for Frontend | ||
const userOrders = async (req, res) => {}; | ||
|
||
// update order status from Admin Panel | ||
const updateStatus = async (req, res) => {}; | ||
|
||
export { | ||
placeOrder, | ||
placeOrderStripe, | ||
placeOrderRazorpay, | ||
allOrders, | ||
userOrders, | ||
updateStatus, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import mongoose from "mongoose"; | ||
|
||
const orderSchema = new mongoose.Schema({ | ||
userId: { type: String, required: true }, | ||
items: { type: Object, required: true }, | ||
amount: { type: Number, required: true }, | ||
address: { type: Object, required: true }, | ||
status: { type: String, required: true, default: "Order Placed" }, | ||
paymentMethod: { type: String, required: true }, | ||
payment: { type: Boolean, required: true, default: false }, | ||
date: { type: Number, required: true }, | ||
}); | ||
|
||
const orderModel = | ||
mongoose.models.order || mongoose.model("order", orderSchema); | ||
export default orderModel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import express from "express"; | ||
import { | ||
placeOrder, | ||
placeOrderStripe, | ||
allOrders, | ||
userOrders, | ||
updateStatus, | ||
} from "../controllers/orderController.js"; | ||
import adminAuth from "../middleware/adminAuth.js"; | ||
import authUser from "../middleware/auth.js"; | ||
|
||
const orderRouter = express.Router(); | ||
|
||
// Admin Features | ||
orderRouter.post("/list", adminAuth, allOrders); | ||
orderRouter.post("/status", adminAuth, updateStatus); | ||
|
||
// Payment Features | ||
orderRouter.post("/place", authUser, placeOrder); | ||
orderRouter.post("/stripe", authUser, placeOrderStripe); | ||
|
||
// user Feature | ||
orderRouter.post("/userorders", authUser, userOrders); | ||
|
||
export default orderRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters