This commit is contained in:
pawan-dot 2022-08-08 17:16:37 +05:30
parent 3263b9d599
commit 4cbcc576a0

View File

@ -9,27 +9,40 @@ import cloudinary from "cloudinary"
import generator from 'generate-password' import generator from 'generate-password'
// 1.Register a User // 1.Register a User
export const registerUser = catchAsyncErrors(async (req, res, next) => { export const registerUser = async (req, res, next) => {
const files = req.files.avatar; try {
const myCloud = await cloudinary.uploader.upload(files.tempFilePath, { const files = req.files.avatar;
folder: "cmp-user/image", const myCloud = await cloudinary.uploader.upload(files.tempFilePath, {
}, folder: "cmp-user/image",
function (error, result) { (result, error) });
const { name, email, password, phone } = req.body;
const user = await User.create({
name,
email,
password,
phone,
avatar: {
public_id: myCloud.public_id,
url: myCloud.secure_url,
}, },
}); function (error, result) { (result, error) });
sendToken(user, 201, res);
}); const { name, email, password, phone } = req.body;
const user = await User.create({
name,
email,
password,
phone,
avatar: {
public_id: myCloud.public_id,
url: myCloud.secure_url,
},
});
sendToken(user, 201, res);
} catch (e) {
// console.log(e.message);
if (e.toString().includes('E11000 duplicate key error collection')) {
return res.status(400).json({
status: 'User Already Exists'
});
}
return res
.status(400)
.json({ status: 'Error Communicating with server' });
}
};
// 2.Login User // 2.Login User
export const loginUser = catchAsyncErrors(async (req, res, next) => { export const loginUser = catchAsyncErrors(async (req, res, next) => {