fixing small problems regarding api functionality
This commit is contained in:
parent
7a38575ffc
commit
10f7f8c91a
|
|
@ -112,17 +112,31 @@ const postUserController = (req, res, next, config) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const putUserController = (req, res, next, config) => {
|
const putUserController = async (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 {
|
||||||
|
let updatedData = { uuid }
|
||||||
|
|
||||||
|
if (username) updatedData.username = username
|
||||||
|
if (email) updatedData.email = email
|
||||||
|
if (fk_role) updatedData.fk_role = fk_role
|
||||||
|
|
||||||
|
if (password) {
|
||||||
|
const hashedPassword = await bcrypt.hash(password, 10)
|
||||||
|
updatedData.password = hashedPassword
|
||||||
|
}
|
||||||
|
|
||||||
|
const users = await modifyUserModel({ ...updatedData, conn })
|
||||||
|
|
||||||
modifyUserModel({ ...req.body, uuid, conn })
|
|
||||||
.then((users) => {
|
|
||||||
if (noResults(users)) {
|
if (noResults(users)) {
|
||||||
const err = error404()
|
const err = error404()
|
||||||
const error = errorHandler(err, config.environment)
|
const error = errorHandler(err, config.environment)
|
||||||
return sendResponseNotFound(res, error)
|
return sendResponseNotFound(res, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
_data: {
|
_data: {
|
||||||
message: 'User modified',
|
message: 'User modified',
|
||||||
|
|
@ -130,14 +144,13 @@ const putUserController = (req, res, next, config) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
next(result)
|
next(result)
|
||||||
})
|
|
||||||
.catch((err) => {
|
} catch (err) {
|
||||||
const error = errorHandler(err, config.environment)
|
const error = errorHandler(err, config.environment)
|
||||||
return res.status(error.code).json(error)
|
return 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) => {
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,14 @@ const postCoordinatesController = (req, res, next, config) => {
|
||||||
next(result)
|
next(result)
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
if (err.code === 'ER_DUP_ENTRY') {
|
||||||
|
const error = errorHandler(err, config.environment)
|
||||||
|
return res.status(error.code).json(error)
|
||||||
|
}
|
||||||
|
if (err.code === 'ER_BAD_NULL_ERROR') {
|
||||||
|
const error = error404()
|
||||||
|
return res.status(error.code).json(error)
|
||||||
|
}
|
||||||
const error = errorHandler(err, config.environment)
|
const error = errorHandler(err, config.environment)
|
||||||
return res.status(error.code).json(error)
|
return res.status(error.code).json(error)
|
||||||
})
|
})
|
||||||
|
|
@ -92,6 +100,11 @@ const putCoordinatesController = (req, res, next, config) => {
|
||||||
|
|
||||||
modifyCoordinatesModel({ ...req.body, uuid: uuid_coordinates, conn })
|
modifyCoordinatesModel({ ...req.body, uuid: uuid_coordinates, conn })
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
if (noResults(response)) {
|
||||||
|
const err = error404()
|
||||||
|
const error = errorHandler(err, config.environment)
|
||||||
|
return sendResponseNotFound(res, error)
|
||||||
|
}
|
||||||
const result = {
|
const result = {
|
||||||
_data: {
|
_data: {
|
||||||
coordinates: response
|
coordinates: response
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ const getUserHasPlacesByUserUuidController = (req, res, next, config) => {
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
const error = errorHandler(err, config.environment)
|
const error = errorHandler(err, config.environment)
|
||||||
res.status(error.code).json(error)
|
return res.status(error.code).json(error)
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
mysql.end(conn)
|
mysql.end(conn)
|
||||||
|
|
@ -114,7 +114,7 @@ const getUserHasPlacesByPlaceUuidController = (req, res, next, config) => {
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
const error = errorHandler(err, config.environment)
|
const error = errorHandler(err, config.environment)
|
||||||
res.status(error.code).json(error)
|
return res.status(error.code).json(error)
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
mysql.end(conn)
|
mysql.end(conn)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue