Update Account Details¶
const updateAccountDetails = asyncHandler(async (req, res) => {
const { fullname, email } = req.body;
if (!fullname && !email) {
throw new ApiError(400, "fullname or email is required");
}
const user = await User.findByIdAndUpdate(
req.user._id,
{
$set: {
fullname,
email: email,
},
},
{ new: true }
).select("-password -refreshToken");
return res
.status(200)
.json(new ApiResponse(200, user, "Account Details updated"));
});
¶
const updateAccountDetails = asyncHandler(async (req, res) => {
const { fullname, email } = req.body;
if (!fullname && !email) {
throw new ApiError(400, "fullname or email is required");
}
const user = await User.findByIdAndUpdate(
req.user._id,
{
$set: {
fullname,
email: email,
},
},
{ new: true }
).select("-password -refreshToken");
return res
.status(200)
.json(new ApiResponse(200, user, "Account Details updated"));
});
Update User Avatar¶
const updateUserAvatar = asyncHandler(async (req, res) => {
const avatarLocalPath = req.file?.path;
if (!avatarLocalPath) {
throw new ApiError(400, "Avatar file is missing");
}
const avatar = await uploadOnCloudinary(avatarLocalPath);
if (!avatar.url) {
throw new ApiError(500, "Something went wrong while uploading avatar");
}
const user = await User.findByIdAndUpdate(
req.user?._id,
{
$set: {
avatar: avatar.url,
},
},
{ new: true }
).select("-password -refreshToken");
return res.status(200).json(new ApiResponse(200, user, "Avatar updated"));
});
¶
const updateUserAvatar = asyncHandler(async (req, res) => {
const avatarLocalPath = req.file?.path;
if (!avatarLocalPath) {
throw new ApiError(400, "Avatar file is missing");
}
const avatar = await uploadOnCloudinary(avatarLocalPath);
if (!avatar.url) {
throw new ApiError(500, "Something went wrong while uploading avatar");
}
const user = await User.findByIdAndUpdate(
req.user?._id,
{
$set: {
avatar: avatar.url,
},
},
{ new: true }
).select("-password -refreshToken");
return res.status(200).json(new ApiResponse(200, user, "Avatar updated"));
});