-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
just a normal commit for the presentation requirement
- Loading branch information
1 parent
3592e01
commit 790b078
Showing
5 changed files
with
65 additions
and
3 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,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.
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
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,7 @@ | ||
import mongoose, {Schema} from "mongoose" | ||
|
||
const cartSchema = new Schema({ | ||
|
||
}, {timestamps: true}); | ||
|
||
const Cart = mongoose.model("Cart", cartSchema); |
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