Skip to content

Commit

Permalink
just a normal commit for the presentation requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
beingPro007 committed Oct 9, 2024
1 parent 3592e01 commit 790b078
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 3 deletions.
55 changes: 55 additions & 0 deletions src/controllers/order.controllers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Order } from "../models/orders.models";
import { ApiError } from "../utils/ApiError";
import { asynchandler } from "../utils/asynchandler";

const getOrders = asynchandler(async(req, res) => {
const page = Number(req.query.pageNumber) || 1;
const pageSize = 3;
const userId = req.user?._id;

if(!userId){
throw new ApiError(400, "User not found you need to login first")
}

const allOrders = Order.aggregate([
{
$match: {
orderedBy: ObjectId(`${userId}`),
},
},
{
$project: {
prodName: 1,
images: 1,
orderStatus: 1,
price : 1,
qty: 1,
grandTotal: 1,
createdAt: 1,
},
},
{
$sort: {
createdAt: -1,
}
},
{
$skip: pageSize * (page - 1),
},
{
$limit: 3,
}
]);

if(!allOrders){
throw new ApiError(400, "No order found")
}

res.status(200)
.json(new ApiResponse(
200,
"All Order fetched Successfully!",
allOrders
));

})
Empty file.
4 changes: 2 additions & 2 deletions src/controllers/product.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ const deleteProduct = asynchandler(async (req, res) => {
);
});


const buyNow = asynchandler(async (req, res) => {
const userId = req.user?._id;

Expand All @@ -207,6 +208,7 @@ const buyNow = asynchandler(async (req, res) => {
const order = await Order.create({
orderedBy: userId,
product: prodId,
prodName: product.prodName,
price: product.price,
qty: qty,
orderStatus: 'Pending',
Expand All @@ -231,6 +233,4 @@ const buyNow = asynchandler(async (req, res) => {
}
});



export { addProduct, getCategoryProducts, updateProductDetails, deleteProduct, buyNow };
7 changes: 7 additions & 0 deletions src/models/cart.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import mongoose, {Schema} from "mongoose"

const cartSchema = new Schema({

}, {timestamps: true});

const Cart = mongoose.model("Cart", cartSchema);
2 changes: 1 addition & 1 deletion src/models/product.models.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const productSchema = new Schema(
{
prodName: {
type: String,
required: true,
required: false,
index: true,
unique: true, // Ensures product names are unique
},
Expand Down

0 comments on commit 790b078

Please sign in to comment.