This is probably something a very small problem but I can't find its solution so please bear with me!
I don't understand why at const body = ctx.request.body ctx becomes undefined. Before it carried over this from the create() function which calls createEntity().
What am I doing wrong?
I'm calling a function createEntitylike this:
module.exports = {
createEntity: () => {
var ctx = this // both ctx and this are fine
return new Promise((resolve, reject) => {
const body = ctx.request.body // <-- ctx is undefined
resolve();
})
}
}
create() calls createEntity(). It is a generator function wrapped with co()via Koa.js
create: function * () {
this.body = yield createEntity.call(this)
}
EDIT: Here's a screenshot why I thought this is fine after calling createEntity:
