import Account from '@apps/maha/models/account'

const getAccounts = async (req, params) => {

  const { filter, page } = params

  return await Account.filterFetch({
    distinct: ['maha_accounts.id'],
    aliases: {
      app_id: 'maha_roles_apps.app_id',
      right_id: 'maha_roles_rights.right_id',
      team_id: 'maha_users.team_id'
    },
    filter: {
      params: filter,
      search: ['first_name','last_name','email']
    },
    sort: {
      defaults: 'last_name',
      allowed: ['last_name']
    },
    page,
    withRelated: ['photo'],
    transacting: req.trx
  })

}

export default getAccounts
