Remove profileImage from returned user
This commit is contained in:
1 parent
3a1bd48d89
commit
59992b4ac8
1 file changed
+10
-4
+10
-4
@@ -42,7 +42,9 @@ const insertUser = async (req, res) => {
|
|||||||
}
|
}
|
||||||
const newUser = new UserModel(userData);
|
const newUser = new UserModel(userData);
|
||||||
await newUser.save();
|
await newUser.save();
|
||||||
return await UserModel.findOne({ _id: newUser._id }).select("-password"); // .select() doesn't work with create, need to save then find
|
return await UserModel.findOne({ _id: newUser._id })
|
||||||
|
.select("-password")
|
||||||
|
.select("-profileImage"); // .select() doesn't work with create, need to save then find
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code === DUPLICATE_KEY_CODE) {
|
if (error.code === DUPLICATE_KEY_CODE) {
|
||||||
throw new Error(errorMessages.DB_USER_EXISTS);
|
throw new Error(errorMessages.DB_USER_EXISTS);
|
||||||
@@ -65,8 +67,10 @@ const insertUser = async (req, res) => {
|
|||||||
const getUserByEmail = async (req, res) => {
|
const getUserByEmail = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
// Need the password to be able to compare, removed .select()
|
// Need the password to be able to compare, removed .select()
|
||||||
// We can strip the hash before returing the user
|
// PW hash is removed in controller
|
||||||
const user = await UserModel.findOne({ email: req.body.email });
|
const user = await UserModel.findOne({ email: req.body.email }).select(
|
||||||
|
"-profileImage"
|
||||||
|
);
|
||||||
if (user) {
|
if (user) {
|
||||||
return user;
|
return user;
|
||||||
} else {
|
} else {
|
||||||
@@ -102,7 +106,9 @@ const updateUser = async (req, res) => {
|
|||||||
candidateUserId,
|
candidateUserId,
|
||||||
candidateUser,
|
candidateUser,
|
||||||
{ new: true } // Returns updated user instead of pre-update user
|
{ new: true } // Returns updated user instead of pre-update user
|
||||||
).select("-password");
|
)
|
||||||
|
.select("-password")
|
||||||
|
.select("-profileImage");
|
||||||
return updatedUser;
|
return updatedUser;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
Reference in new issue
Block a user