address save in order

This commit is contained in:
pawan-dot 2023-12-12 18:04:57 +05:30
parent 751f90e1db
commit 1d885ea074
2 changed files with 28 additions and 12 deletions

View File

@ -13,14 +13,14 @@ export const getAllOrder = async (req, res) => {
select: "name -_id",
})
.populate({
path: "shippingInfo",
path: "shippingInfo.addressId",
// populate: {
// path: "Franchisee",
// select: "banner price_Lable ",
// },
})
.sort({ createdAt: -1 });
.sort({ updatedAt: -1 });
if (order) {
res.status(201).json({
success: true,
@ -47,7 +47,7 @@ export const getSingleOrder = async (req, res) => {
select: "name -_id",
})
.populate({
path: "shippingInfo",
path: "shippingInfo.addressId",
})
.sort({ createdAt: -1 });
if (order) {
@ -72,7 +72,7 @@ export const getUserSelf = async (req, res) => {
user: req.user._id,
payment_status: "success",
})
.populate("shippingInfo")
.populate("shippingInfo.addressId")
.sort({ createdAt: -1 });
if (order) {
return res.status(200).json({
@ -147,13 +147,27 @@ export const updateOrderStatusById = async (req, res) => {
// { status: body.status, "status_timeline.delivered": currentDate }
// );
// }
await Order.findByIdAndUpdate(order._id, body);
// console.log(order);
res
.status(200)
.json({ status: "ok", message: "Order status updated successfully!" });
if (req.body.status === "dispatched") {
body["courier_name"] = req.body.courierName;
body["courier_tracking_id"] = req.body.TrackingID;
await Order.findByIdAndUpdate(order._id, body);
return res
.status(200)
.json({ status: "ok", message: "Order status updated successfully!" });
} else if (req.body.status === "delivered") {
body["isDelivered"] = true;
body["DeliveredDate"] = req.body.DDate;
await Order.findByIdAndUpdate(order._id, body);
return res
.status(200)
.json({ status: "ok", message: "Order status updated successfully!" });
} else {
await Order.findByIdAndUpdate(order._id, body);
// console.log(order);
res
.status(200)
.json({ status: "ok", message: "Order status updated successfully!" });
}
} catch (error) {
console.log(error);
res

View File

@ -131,6 +131,8 @@ const orderSchema = new mongoose.Schema(
// paypal_signature: { type: String },
// order_used: { type: Boolean, default: false },
isDelivered: { type: Boolean, required: true, default: false },
DeliveredDate: { type: String, default: "" },
// deliveredAt: { type: Date },
status_timeline: {
new: { type: Date },
@ -141,7 +143,7 @@ const orderSchema = new mongoose.Schema(
returned: { type: Date },
},
courier_name: { type: String },
tracking_id: { type: String },
courier_tracking_id: { type: String },
},
{ timestamps: true }
);