rhwilr/adonis-bumblebee

Suggestion: make include{Name} method name accept context as second param

Closed this issue · 1 comments

I belive this is sometimes needed.
For example, you want to transform users who have posts.
Posts can have status of unpublished, and when fetching a list of users you shouldn't see unpublished posts attached to a user. But, if you are an admin or you are a user that is accessing his own profile (logged in user). You would for example like to see all unpublished posts also.

This would be easy to implement if include{Name} could also have access to ctx param. For example:

includePosts(model, ctx) {
    const currentUser = ctx.auth.getUser()
    let query = model.posts()
    if(currentUser) {
            // modify query to your liking...
    } else {
            // make default query, not including for example unpublished posts
    }

    return this.collection(query.fetch(), TagTransformer)
}

Added this feature in release v1.1.0