# All files / src/api events.coffee

44.44% Statements 4/9
100% Branches 0/0
0% Functions 0/1
44.44% Lines 4/9

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    171x
    1x
    1x

    1x

     Event = require('../model/events').Event
    authorisation = require './authorisation'
    utils = require "../utils"

    exports.getLatestEvents = (receivedTime) ->
      if not authorisation.inGroup 'admin', this.authenticated
        utils.logAndSetResponse this, 403, "User #{this.authenticated.email} is not an admin, API access to events denied.", 'info'
        return

      try
        rtDate = new Date(Number(receivedTime))
        results = yield Event.find({ 'created': { '$gte': rtDate } }).sort({ 'normalizedTimestamp': 1 }).exec()
        this.body = events: results
      catch err
        utils.logAndSetResponse this, 500, "Could not fetch the latest events via the API: #{err}", 'error'