This repository has been archived on 2025-11-04. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
know-it-all/server/routes/auth/UpdateUserDetails.js
2022-03-05 19:10:17 -06:00

28 lines
717 B
JavaScript

const { Op } = require('sequelize');
const { User } = require('../../models/index');
async function UpdateUserDetails(req, res, next) {
const { token, ...body } = req.body;
if (body.email) {
const result = await User.findOne({
where: {
[Op.and]: {
email: body.email,
userID: { [Op.not]: req.user.userID },
},
},
});
if (result) {
return res
.status(400)
.send('A user with that email already exists.');
}
}
req.user.update({ ...body });
return res.send('Account details changed.');
}
module.exports = UpdateUserDetails;