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