fixed user update for problem with role update
This commit is contained in:
parent
b827eff9df
commit
8297962644
|
|
@ -104,45 +104,32 @@ const postUserController = (req, res, next, config) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const putUserController = async (req, res, next, config) => {
|
const putUserController = (req, res, next, config) => {
|
||||||
const conn = mysql.start(config)
|
const conn = mysql.start(config)
|
||||||
const uuid = req.params.uuid
|
const uuid = req.params.uuid
|
||||||
const { username, password, email, fk_role } = req.body
|
|
||||||
|
|
||||||
try {
|
modifyUserModel({ ...req.body, uuid, conn })
|
||||||
let updatedData = { uuid }
|
.then((users) => {
|
||||||
|
if (noResults(users)) {
|
||||||
if (username) updatedData.username = username
|
const err = error404()
|
||||||
if (email) updatedData.email = email
|
const error = errorHandler(err, config.environment)
|
||||||
if (fk_role) updatedData.fk_role = fk_role
|
return sendResponseNotFound(res, error)
|
||||||
|
}
|
||||||
if (password) {
|
const result = {
|
||||||
const hashedPassword = await bcrypt.hash(password, 10)
|
_data: {
|
||||||
updatedData.password = hashedPassword
|
message: 'User modified',
|
||||||
}
|
users
|
||||||
|
}
|
||||||
const users = await modifyUserModel({ ...updatedData, conn })
|
|
||||||
|
|
||||||
if (noResults(users)) {
|
|
||||||
const err = error404()
|
|
||||||
const error = errorHandler(err, config.environment)
|
|
||||||
return sendResponseNotFound(res, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = {
|
|
||||||
_data: {
|
|
||||||
message: 'User modified',
|
|
||||||
users
|
|
||||||
}
|
}
|
||||||
}
|
next(result)
|
||||||
next(result)
|
})
|
||||||
|
.catch((err) => {
|
||||||
} catch (err) {
|
const error = errorHandler(err, config.environment)
|
||||||
const error = errorHandler(err, config.environment)
|
res.status(error.code).json(error)
|
||||||
res.status(error.code).json(error)
|
})
|
||||||
} finally {
|
.finally(() => {
|
||||||
mysql.end(conn)
|
mysql.end(conn)
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const softDeleteUserController = (req, res, next, config) => {
|
const softDeleteUserController = (req, res, next, config) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue