text: import AddonSerializer from '@apps/subscriptions/serializers/addon_serializer'
  import Service from '@apps/subscriptions/models/service'
  import Addon from '@apps/subscriptions/models/addon'
  import Plan from '@apps/subscriptions/models/plan'
  
  const listRoute = async (req, res) => {
  
    const service = await Service.query(qb => {
      qb.where('team_id', req.team.get('id'))
      qb.where('id', req.params.service_id)
    }).fetch({
      transacting: req.trx
    })
  
    if(!service) return res.status(404).respond({
      code: 404,
      message: 'Unable to load service'
    })
  
    const plan = await Plan.query(qb => {
      qb.where('team_id', req.team.get('id'))
      qb.where('id', req.params.plan_id)
    }).fetch({
      transacting: req.trx
    })
  
    if(!plan) return res.status(404).respond({
      code: 404,
      message: 'Unable to load plan'
    })
  
    const addons = await Addon.filterFetch({
      scope: (qb) => {
        qb.where('team_id', req.team.get('id'))
        qb.where('plan_id', plan.get('id'))
      },
      filter: {
        params: req.query.$filter,
        search: ['title']
      },
      sort: {
        params: req.query.$sort,
        defaults: ['-created_at']
      },
      page: req.query.$page,
      transacting: req.trx
    })
  
    await res.status(200).respond(addons, AddonSerializer)
  
  }
  
  export default listRoute
  