text: import StageSerializer from '@apps/sales/serializers/stage_serializer'
  import Pipeline from '@apps/sales/models/pipeline'
  import Stage from '@apps/sales/models/stage'
  
  const stagesRoute = async (req, res) => {
  
    const pipeline = await Pipeline.query(qb => {
      qb.joinRaw('inner join crm_program_user_access on crm_program_user_access.program_id=sales_pipelines.program_id and crm_program_user_access.user_id=?', req.user.get('id'))
      qb.where('team_id', req.team.get('id'))
      qb.where('id', req.params.id)
    }).fetch({
      transacting: req.trx
    })
  
    if(!pipeline) return res.status(404).respond({
      code: 404,
      message: 'Unable to load pipeline'
    })
  
    const stages = await Stage.filterFetch({
      scope: (qb) => {
        qb.where('team_id', req.team.get('id'))
        qb.where('pipeline_id', pipeline.get('id'))
      },
      sort: {
        defaults: 'delta'
      },
      page: req.query.$page,
      transacting: req.trx
    })
  
    await res.status(200).respond(stages, StageSerializer)
  
  }
  
  export default stagesRoute
  