text: import DatasetSerializer from '@apps/datasets/serializers/dataset_serializer'
  import socket from '@core/services/routes/emitter'
  import Dataset from '@apps/datasets/models/dataset'
  
  const updateRoute = async (req, res) => {
  
    const dataset = await Dataset.query(qb => {
      qb.where('id', req.params.dataset_id)
    }).fetch({
      transacting: req.trx
    })
  
    if(!dataset) return res.status(404).respond({
      code: 404,
      message: 'Unable to load dataset'
    })
  
    await dataset.save({
      config: {
        ...dataset.get('config'),
        ...req.body.config
      }
    },{
      transacting: req.trx,
      patch: true
    })
  
    await Promise.mapSeries(Object.keys(req.body.types), async(type_id) => {
      await req.trx('datasets_types').where('id', type_id).update({
        config: req.body.types[type_id]
      })
    })
  
    await socket.refresh(req, [
      `/admin/datasets/datasets/${dataset.get('id')}`,
      `/admin/datasets/datasets/${dataset.get('id')}/api`
    ])
  
    await res.status(200).respond(dataset, DatasetSerializer)
  
  }
  
  export default updateRoute
  