       'send invitations' : ['moderator', 'admin']
     indexes         :
       code          : 'unique'
-      # TODO create a compound index on groupName and
+      # email         : 'ascending'
+      # groupName     : 'ascending'
+      #
+      # TODO(cihagir) create a compound unique index on groupName and email
     sharedMethods   :
 
       instance:

        type        : Date
        default     : -> new Date

  # remove deleted invitation from database
  remove$: permit 'send invitations',
    success: (client, callback) ->
      @remove callback

  accept$: secure (client, callback) ->
    { delegate } = client.connection
    @accept delegate, callback

  accept: (account, callback) ->
    operation = $set : { status: 'accepted' }
    @update operation, callback


  # some selects result set for invitations, it adds group name automatically
  @some$:  permit 'send invitations',

      console.log selector, options
      JInvitation.some selector, options, callback

  # search searches database with given query string, adds `starting
  # with regex` around query param
  @search$:  permit 'send invitations',
    success: (client, query, options, callback) ->
      selector = { $or : [ {'name' : ///^#{query}/// }, {'email' : ///^#{query}/// } ]}
