 ###
 # Deletes a specific channels details
 ###
-exports.removeChannel = `function *removeChannel(channelId) {
+exports.removeChannel = (channelId) ->
 
-  // Test if the user is authorised
-  if (authorisation.inGroup('admin', this.authenticated) === false) {
-    logger.info('User ' +this.authenticated.email+ ' is not an admin, API access to removeChannel denied.')
-    this.body = 'User ' +this.authenticated.email+ ' is not an admin, API access to removeChannel denied.'
-    this.status = 'forbidden';
-    return;
-  }
+  # Test if the user is authorised
+  if authorisation.inGroup('admin', this.authenticated) is false
+    utils.logAndSetResponse this, 'forbidden', "User #{this.authenticated.email} is not an admin, API access to removeChannel denied.", 'info'
+    return
 
-  // Get the values to use
-  var id = unescape(channelId);
+  # Get the values to use
+  id = unescape channelId
 
-  try {
-    var numExistingTransactions = yield Transaction.count({ channelID: id }).exec();
+  try
+    numExistingTransactions = yield Transaction.count({ channelID: id }).exec()
 
-    // Try to get the channel (Call the function that emits a promise and Koa will wait for the function to complete)
-    var channel;
-    if (numExistingTransactions === 0) {
-      //safe to remove
-      channel = yield Channel.findByIdAndRemove(id).exec();
-    } else {
-      //not safe to remove. just flag as deleted
-      channel = yield Channel.findByIdAndUpdate(id, { status: 'deleted' }).exec();
-    }
+    # Try to get the channel (Call the function that emits a promise and Koa will wait for the function to complete)
+    channel
+    if numExistingTransactions is 0
+      # safe to remove
+      channel = yield Channel.findByIdAndRemove(id).exec()
+    else
+      # not safe to remove. just flag as deleted
+      channel = yield Channel.findByIdAndUpdate(id, { status: 'deleted' }).exec()
 
-    // All ok! So set the result
-    this.body = 'The channel was successfully deleted';
-    logger.info('User %s removed channel with id %s', this.authenticated.email, id);
+    # All ok! So set the result
+    this.body = 'The channel was successfully deleted'
+    logger.info "User #{this.authenticated.email} removed channel with id #{id}"
 
-    processPostDeleteTriggers(channel);
-  }
-  catch (e) {
-    // Error! So inform the user
-    logger.error('Could not remove channel by id: ' +id+ ' via the API: ' + e);
-    this.body = e.message;
-    this.status = 'internal server error';
-  }
-}`
+    processPostDeleteTriggers channel
+  catch err
+    # Error! So inform the user
+    utils.logAndSetResponse this, 'internal server error', "Could not remove channel by id: #{id} via the API: #{e}", 'error'

###
# Retrieves the list of active channels
###
exports.getChannels = `function *getChannels() {
  try {
    this.body = yield authorisation.getUserViewableChannels(this.authenticated);
  }
  catch (e) {
    // Error! So inform the user
    logger.error('Could not fetch all channels via the API: ' + e);
    this.body = e.message;
    this.status = 'internal server error';
  }
}`


processPostAddTriggers = (channel) ->
  if channel.type and authMiddleware.isChannelEnabled channel

      else
        polling.removePollingChannel channel, (err) -> logger.error err if err

###
# Updates the details for a specific channel
###
exports.updateChannel = (channelId) ->

  # Test if the user is authorised
  if authorisation.inGroup('admin', this.authenticated) is false
    utils.logAndSetResponse this, 'forbidden', "User #{this.authenticated.email} is not an admin, API access to updateChannel denied.", 'info'
    return

  # Get the values to use
  id = unescape channelId
  channelData = this.request.body

  # Ignore _id if it exists, user cannot change the internal id
  if typeof channelData._id isnt 'undefined'
    delete channelData._id

  if not isPathValid channelData
    utils.logAndSetResponse this, 'bad request', 'Channel cannot have both path and pathTransform. pathTransform must be of the form s/from/to[/g]', 'info'
    return

  try
    channel = yield Channel.findByIdAndUpdate(id, channelData).exec()

    # All ok! So set the result
    this.body = 'The channel was successfully updated'
    logger.info 'User %s updated channel with id %s', this.authenticated.email, id

    processPostUpdateTriggers channel
  catch err
    # Error! So inform the user
    utils.logAndSetResponse this, 'internal server error', "Could not update channel by id: #{id} via the API: #{e}", 'error'

processPostDeleteTriggers = (channel) ->
  if channel.type
