text: import * as constantcontact from '@core/services/constantcontact'
  import * as qualtrics from '@core/services/qualtrics'
  import * as microsoft from '@core/services/microsoft'
  import * as mailchimp from '@core/services/mailchimp'
  import * as adobesign from '@core/services/adobesign'
  import socket from '@core/services/routes/emitter'
  import * as dropbox from '@core/services/dropbox'
  import * as google from '@core/services/google'
  import Profile from '@apps/maha/models/profile'
  import * as box from '@core/services/box'
  import moment from 'moment'
  
  const getService = (service) => {
    if(_.includes(['googledrive','googlecontacts','gmail'], service)) return google
    if(_.includes(['outlook','onedrive'], service)) return microsoft
    if(service === 'constantcontact') return constantcontact
    if(service === 'qualtrics') return qualtrics
    if(service === 'mailchimp') return mailchimp
    if(service === 'dropbox') return dropbox
    if(service === 'adobesign') return adobesign
    if(service === 'box') return box
    return null
  }
  
  const destroyRoute = async (req, res) => {
  
    const profile = await Profile.query(qb => {
      qb.where('account_id', req.account.get('id'))
      qb.where('id', req.params.id )
      qb.whereNull('deleted_at')
    }).fetch({
      transacting: req.trx
    })
  
    if(!profile) return res.status(404).json({
      code: 404,
      message: 'Unable to find profile'
    })
  
    const service = await getService(profile.get('source'))
  
    if(profile.get('type') === 'email') {
      await service.unsubscribe(req, {
        profile
      })
    }
  
    if(service.revoke) {
      try {
        await service.revoke(req, {
          profile
        })
      } catch(e) {}
    }
  
    await profile.save({
      data: null,
      deleted_at: moment()
    }, {
      transacting: req.trx,
      patch: true
    })
  
    await socket.refresh(req, {
      channel: 'user',
      target: '/admin/account/profiles'
    })
  
    await res.status(200).respond(true)
  
  }
  
  export default destroyRoute
  