view of customer done
This commit is contained in:
parent
e7d068798d
commit
f49d790e82
@ -53,7 +53,7 @@ export const AddshippingAddress = async (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// For website
|
||||||
export const getSingleUserSippingAddress = async (req, res) => {
|
export const getSingleUserSippingAddress = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const UserShippingAddress = await shippingAddress
|
const UserShippingAddress = await shippingAddress
|
||||||
@ -74,6 +74,27 @@ export const getSingleUserSippingAddress = async (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// For Admin
|
||||||
|
export const getSingleUserSippingAddressForAdmin = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const UserShippingAddress = await shippingAddress
|
||||||
|
.find({ user: req.params._id })
|
||||||
|
|
||||||
|
.sort({ createdAt: -1 });
|
||||||
|
if (UserShippingAddress) {
|
||||||
|
res.status(201).json({
|
||||||
|
success: true,
|
||||||
|
UserShippingAddress,
|
||||||
|
message: "All User Shipping Address Fetched",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message ? error.message : "Something went Wrong",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
export const deleteSelfShippingAddress = async (req, res) => {
|
export const deleteSelfShippingAddress = async (req, res) => {
|
||||||
|
@ -3,8 +3,9 @@ import {
|
|||||||
AddshippingAddress,
|
AddshippingAddress,
|
||||||
getSingleUserSippingAddress,
|
getSingleUserSippingAddress,
|
||||||
deleteSelfShippingAddress,
|
deleteSelfShippingAddress,
|
||||||
|
getSingleUserSippingAddressForAdmin,
|
||||||
} from "./ShippingAddressController.js";
|
} from "./ShippingAddressController.js";
|
||||||
import { isAuthenticatedUser } from "../../middlewares/auth.js";
|
import { authorizeRoles, isAuthenticatedUser } from "../../middlewares/auth.js";
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
router.route("/new").post(isAuthenticatedUser, AddshippingAddress);
|
router.route("/new").post(isAuthenticatedUser, AddshippingAddress);
|
||||||
@ -12,6 +13,14 @@ router
|
|||||||
.route("/user/address/")
|
.route("/user/address/")
|
||||||
.get(isAuthenticatedUser, getSingleUserSippingAddress);
|
.get(isAuthenticatedUser, getSingleUserSippingAddress);
|
||||||
|
|
||||||
|
router
|
||||||
|
.route("/user/address/:_id")
|
||||||
|
.get(
|
||||||
|
isAuthenticatedUser,
|
||||||
|
authorizeRoles("admin"),
|
||||||
|
getSingleUserSippingAddressForAdmin
|
||||||
|
);
|
||||||
|
|
||||||
router
|
router
|
||||||
.route("/delete/:id")
|
.route("/delete/:id")
|
||||||
.delete(isAuthenticatedUser, deleteSelfShippingAddress);
|
.delete(isAuthenticatedUser, deleteSelfShippingAddress);
|
||||||
|
@ -201,24 +201,36 @@ export const getUserDetails = catchAsyncErrors(async (req, res, next) => {
|
|||||||
user,
|
user,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
export const getAllUsers = catchAsyncErrors(async (req, res, next) => {
|
|
||||||
const users = await User.find().populate("orders"); // Assuming orders are stored in a separate collection and populated in the User model
|
|
||||||
|
|
||||||
// Process user data to calculate last purchase date and order count
|
// export const getUserDetailsForAdmin = catchAsyncErrors(
|
||||||
const usersWithInfo = users.map((user) => {
|
// async (req, res, next) => {
|
||||||
const lastPurchase =
|
// const user = await User.findById(req.params._id);
|
||||||
user.orders.length > 0
|
|
||||||
? user.orders[user.orders.length - 1].createdAt
|
|
||||||
: null;
|
|
||||||
const orderCount = user.orders.length;
|
|
||||||
return { ...user.toJSON(), lastPurchase, orderCount };
|
|
||||||
});
|
|
||||||
|
|
||||||
res.status(200).json({
|
// res.status(200).json({
|
||||||
success: true,
|
// success: true,
|
||||||
users: usersWithInfo,
|
// user,
|
||||||
});
|
// });
|
||||||
});
|
// }
|
||||||
|
// );
|
||||||
|
|
||||||
|
// export const getAllUsers = catchAsyncErrors(async (req, res, next) => {
|
||||||
|
// const users = await User.find().populate("orders"); // Assuming orders are stored in a separate collection and populated in the User model
|
||||||
|
|
||||||
|
// // Process user data to calculate last purchase date and order count
|
||||||
|
// const usersWithInfo = users.map((user) => {
|
||||||
|
// const lastPurchase =
|
||||||
|
// user.orders.length > 0
|
||||||
|
// ? user.orders[user.orders.length - 1].createdAt
|
||||||
|
// : null;
|
||||||
|
// const orderCount = user.orders.length;
|
||||||
|
// return { ...user.toJSON(), lastPurchase, orderCount };
|
||||||
|
// });
|
||||||
|
|
||||||
|
// res.status(200).json({
|
||||||
|
// success: true,
|
||||||
|
// users: usersWithInfo,
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
|
||||||
// 7.Get single user (admin)
|
// 7.Get single user (admin)
|
||||||
export const getSingleUser = catchAsyncErrors(async (req, res, next) => {
|
export const getSingleUser = catchAsyncErrors(async (req, res, next) => {
|
||||||
@ -244,7 +256,7 @@ export const getUserOrderForAdmin = async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
const order = await Order.find({
|
const order = await Order.find({
|
||||||
user: id,
|
user: id,
|
||||||
payment_status: "success",
|
// payment_status: "success",
|
||||||
}).sort({ createdAt: -1 });
|
}).sort({ createdAt: -1 });
|
||||||
|
|
||||||
if (order) {
|
if (order) {
|
||||||
|
@ -27,6 +27,7 @@ router.route("/user/password/reset/:token").put(resetPassword);
|
|||||||
router.route("/user/logout").get(logout);
|
router.route("/user/logout").get(logout);
|
||||||
|
|
||||||
router.route("/user/details").get(isAuthenticatedUser, getUserDetails);
|
router.route("/user/details").get(isAuthenticatedUser, getUserDetails);
|
||||||
|
|
||||||
router
|
router
|
||||||
.route("/admin/users")
|
.route("/admin/users")
|
||||||
.get(isAuthenticatedUser, authorizeRoles("admin"), getAllUser);
|
.get(isAuthenticatedUser, authorizeRoles("admin"), getAllUser);
|
||||||
|
Loading…
Reference in New Issue
Block a user