Object returns true data but object.key returns undefined or nothing


#1
const findCodeUser = Code
                    .query()
                    .where('code', body.code)
                    .where('user_id', user.id)
                    .first()

                const reqData = findCodeUser
                return reqData.id

#2

You have to prefix the query with await here.

const findCodeUser = await Code
                    .query()
                    .where('code', body.code)
                    .where('user_id', user.id)
                    .first()

Also I don’t understand the concept of re-assigning the query output to a new variable.

const reqData = findCodeUser

You can simply do

return findCodeUser.id

Also the output of a query is not a plain object, in this case it is the instance of a model and you cannot call Object.keys on a class instance, for that you have to get a plain object first.

const reqData = findCodeUser.toJSON()

// below should work now
Object.keys(reqData)