fix: update name of user when firstName or lastName is updated
This commit is contained in:
@@ -103,7 +103,8 @@ export async function updateUserHandler(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const updatedUser = await updateUser(userId, input, req.user);
|
const updatedUser = await updateUser(userId, input, req.user);
|
||||||
if (!updateUser) return res.code(404).send({ error: "resource not found" });
|
if (!updatedUser)
|
||||||
|
return res.code(404).send({ error: "resource not found" });
|
||||||
|
|
||||||
return res.code(200).send(updatedUser);
|
return res.code(200).send(updatedUser);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -182,7 +182,8 @@ export async function updateUser(
|
|||||||
) {
|
) {
|
||||||
throw ErrOpNotValid;
|
throw ErrOpNotValid;
|
||||||
}
|
}
|
||||||
return await userModel
|
|
||||||
|
const userInDb = await userModel
|
||||||
.findOneAndUpdate({ pid: userId }, input, {
|
.findOneAndUpdate({ pid: userId }, input, {
|
||||||
new: true,
|
new: true,
|
||||||
})
|
})
|
||||||
@@ -190,6 +191,16 @@ export async function updateUser(
|
|||||||
"_id pid orgId firstName lastName name email role avatar status createdAt createdBy lastLogin"
|
"_id pid orgId firstName lastName name email role avatar status createdAt createdBy lastLogin"
|
||||||
)
|
)
|
||||||
.populate({ path: "orgId", select: "_id pid name avatar" });
|
.populate({ path: "orgId", select: "_id pid name avatar" });
|
||||||
|
|
||||||
|
if (!userInDb) return null;
|
||||||
|
|
||||||
|
const name = userInDb.firstName + " " + userInDb.lastName;
|
||||||
|
if (name != userInDb.name) {
|
||||||
|
userInDb.name = name;
|
||||||
|
await userInDb.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
return userInDb;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateUserInternal(
|
export async function updateUserInternal(
|
||||||
|
|||||||
Reference in New Issue
Block a user