I am trying to access the dataValues section of a JSON object returned by a function that is invoked through an API call:
exports.findOne = (req, res) => {
const id = req.params.id;
Users.findByPk(id)
.then(data => {
if(data){
console.log("data: ", data);
res.send(data);
} else {
res.status(404).send({
message: "Cannot find user with id=${id}"
});
}
})
.catch(err => {
res.status(500).send({
message: err.message || "Error retrieving Tutorial with id=" + id
});
});
};
When I print out the 'data' variable, this is the output:
findOne: Login {
dataValues: {
ID: 20,
username: 'phil_swift',
email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c3b3abaaafb0b4aaa5b783a5afa6bbb7a2b3a6eda0acae">[email protected]</a>',
password: '<ENCRYPTED>',
account_type: 1,
token: null,
token_expiration: null,
require_password_at_login: false
},
_previousDataValues: {
ID: 20,
username: 'phil_swift',
email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f2829a9b9e81859b9486b2949e978a86938297dc919d9f">[email protected]</a>',
password: '<ENCRYPTED>',
account_type: 1,
token: null,
token_expiration: null,
require_password_at_login: false
},
uniqno: 1,
_changed: Set(0) {},
_options: {
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [
'ID',
'username',
'email',
'password',
'account_type',
'token',
'token_expiration',
'require_password_at_login'
]
},
isNewRecord: false
}
However, when I make a GET request from the front end, it returns undefined.
const { dataValues } = await httpCommon.get("/" + this.state.user.userID);
console.log("dataValues: ", dataValues);
Why does this happen and how can I solve it?