       yield Q.ninvoke(new Mediator(mediator), 'save')
       if mediator.defaultChannelConfig
         yield saveDefaultChannelConfig(mediator.defaultChannelConfig);
-    @status = 'created'
-    logger.info "User #{@authenticated.email} created mediator with urn #{mediator.urn}"
+    this.status = 'created'
+    logger.info "User #{this.authenticated.email} created mediator with urn #{mediator.urn}"
   catch err
     if err.name == 'ValidationError'
       utils.logAndSetResponse this, 'bad request', "Could not add Mediator via the API: #{err}", 'error'


exports.getMediator = (mediatorURN) ->
  # Must be admin
  if authorisation.inGroup('admin', @authenticated) is false
    utils.logAndSetResponse this, 'forbidden', "User #{@authenticated.email} is not an admin, API access to getMediator denied.", 'info'
    return

  urn = unescape(mediatorURN)

  try
    result = yield Mediator.findOne({ "urn": urn }).exec()
    if result == null
      @status = 'not found'
    else
      @body = result
  catch err
    logAndSetResponse this, 'internal server error', "Could not fetch mediator using UUID {urn} via the API: #{err}", 'error'



exports.getAllMediators = ->
  # Must be admin
  if not authorisation.inGroup 'admin', this.authenticated
    utils.logAndSetResponse this, 'forbidden', "User #{this.authenticated.email} is not an admin, API access to getAllMediators denied.", 'info'
    return

  try
    this.body = yield Mediator.find().exec()
  catch err
    logAndSetResponse this, 'internal server error', "Could not fetch mediators via the API: #{err}", 'error'

