text: // App Imports
  import params from '../../setup/config/params'
  import { authCheck } from '../../setup/helpers/utils'
  import validate from '../../setup/helpers/validation'
  import Organization from './model'
  
  // Create
  export async function organizationCreate({ params: { name, description = '', domain = '' }, auth }) {
    if(authCheck(auth)) {
      // Validation rules
      const rules = [
        {
          data: { value: name },
          check: 'notEmpty',
          message: 'Please enter valid name.'
        }
      ]
  
      // Validate
      try {
        validate(rules)
      } catch(error) {
        throw new Error(error.message)
      }
  
      try {
        const data = await Organization.create({
          userId: auth.user._id,
          name,
          description,
          domain
        })
  
        return {
          data
        }
      } catch(error) {
        throw new Error(params.common.message.error.server)
      }
    }
  
    throw new Error(params.user.message.error.auth)
  }
  
  // Update product
  export async function organizationUpdate({ params: { id, name, description = '', domain = '' }, auth }) {
    if(authCheck(auth)) {
      // Validation rules
      const rules = [
        {
          data: { value: name },
          check: 'notEmpty',
          message: 'Please enter valid name.'
        }
      ]
  
      // Validate
      try {
        validate(rules)
      } catch(error) {
        throw new Error(error.message)
      }
  
      try {
        const data = await Organization.updateOne(
          { _id: auth.user.organizationId },
          {
            $set: { name, description, domain }
          }
        )
  
        return {
          data
        }
      } catch(error) {
        throw new Error(params.common.message.error.server)
      }
    }
  
    throw new Error(params.user.message.error.auth)
  }
  
  // Delete
  export async function organizationRemove({ params: { id }, auth }) {
    if(authCheck(auth)) {
      // Validation rules
      const rules = [
        {
          data: { value: id },
          check: 'notEmpty',
          message: params.common.message.error.invalidData
        }
      ]
  
      // Validate
      try {
        validate(rules)
      } catch(error) {
        throw new Error(error.message)
      }
  
      try {
        const data = await Organization.remove({
          _id: _id,
          userId: auth.user._id
        })
  
        return {
          data
        }
      } catch(error) {
        throw new Error(params.common.message.error.server)
      }
    }
  
    throw new Error(params.user.message.error.auth)
  }
  