address save in order
This commit is contained in:
parent
751f90e1db
commit
1d885ea074
@ -13,14 +13,14 @@ export const getAllOrder = async (req, res) => {
|
|||||||
select: "name -_id",
|
select: "name -_id",
|
||||||
})
|
})
|
||||||
.populate({
|
.populate({
|
||||||
path: "shippingInfo",
|
path: "shippingInfo.addressId",
|
||||||
|
|
||||||
// populate: {
|
// populate: {
|
||||||
// path: "Franchisee",
|
// path: "Franchisee",
|
||||||
// select: "banner price_Lable ",
|
// select: "banner price_Lable ",
|
||||||
// },
|
// },
|
||||||
})
|
})
|
||||||
.sort({ createdAt: -1 });
|
.sort({ updatedAt: -1 });
|
||||||
if (order) {
|
if (order) {
|
||||||
res.status(201).json({
|
res.status(201).json({
|
||||||
success: true,
|
success: true,
|
||||||
@ -47,7 +47,7 @@ export const getSingleOrder = async (req, res) => {
|
|||||||
select: "name -_id",
|
select: "name -_id",
|
||||||
})
|
})
|
||||||
.populate({
|
.populate({
|
||||||
path: "shippingInfo",
|
path: "shippingInfo.addressId",
|
||||||
})
|
})
|
||||||
.sort({ createdAt: -1 });
|
.sort({ createdAt: -1 });
|
||||||
if (order) {
|
if (order) {
|
||||||
@ -72,7 +72,7 @@ export const getUserSelf = async (req, res) => {
|
|||||||
user: req.user._id,
|
user: req.user._id,
|
||||||
payment_status: "success",
|
payment_status: "success",
|
||||||
})
|
})
|
||||||
.populate("shippingInfo")
|
.populate("shippingInfo.addressId")
|
||||||
.sort({ createdAt: -1 });
|
.sort({ createdAt: -1 });
|
||||||
if (order) {
|
if (order) {
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
@ -147,13 +147,27 @@ export const updateOrderStatusById = async (req, res) => {
|
|||||||
// { status: body.status, "status_timeline.delivered": currentDate }
|
// { status: body.status, "status_timeline.delivered": currentDate }
|
||||||
// );
|
// );
|
||||||
// }
|
// }
|
||||||
|
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);
|
await Order.findByIdAndUpdate(order._id, body);
|
||||||
// console.log(order);
|
// console.log(order);
|
||||||
|
|
||||||
res
|
res
|
||||||
.status(200)
|
.status(200)
|
||||||
.json({ status: "ok", message: "Order status updated successfully!" });
|
.json({ status: "ok", message: "Order status updated successfully!" });
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
res
|
res
|
||||||
|
@ -131,6 +131,8 @@ const orderSchema = new mongoose.Schema(
|
|||||||
// paypal_signature: { type: String },
|
// paypal_signature: { type: String },
|
||||||
// order_used: { type: Boolean, default: false },
|
// order_used: { type: Boolean, default: false },
|
||||||
isDelivered: { type: Boolean, required: true, default: false },
|
isDelivered: { type: Boolean, required: true, default: false },
|
||||||
|
DeliveredDate: { type: String, default: "" },
|
||||||
|
|
||||||
// deliveredAt: { type: Date },
|
// deliveredAt: { type: Date },
|
||||||
status_timeline: {
|
status_timeline: {
|
||||||
new: { type: Date },
|
new: { type: Date },
|
||||||
@ -141,7 +143,7 @@ const orderSchema = new mongoose.Schema(
|
|||||||
returned: { type: Date },
|
returned: { type: Date },
|
||||||
},
|
},
|
||||||
courier_name: { type: String },
|
courier_name: { type: String },
|
||||||
tracking_id: { type: String },
|
courier_tracking_id: { type: String },
|
||||||
},
|
},
|
||||||
{ timestamps: true }
|
{ timestamps: true }
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user