overleaf/services/web/app/coffee/Features/Analytics/AnalyticsController.coffee

43 lines
1.4 KiB
CoffeeScript
Raw Normal View History

2016-09-06 04:29:58 -04:00
AnalyticsManager = require "./AnalyticsManager"
Errors = require "../Errors/Errors"
AuthenticationController = require("../Authentication/AuthenticationController")
InstitutionsAPI = require("../Institutions/InstitutionsAPI")
GeoIpLookup = require '../../infrastructure/GeoIpLookup'
2016-08-10 11:42:56 -04:00
module.exports = AnalyticsController =
2018-01-22 11:20:08 -05:00
updateEditingSession: (req, res, next) ->
userId = AuthenticationController.getLoggedInUserId(req)
projectId = req.params.projectId
countryCode = null
if userId?
GeoIpLookup.getDetails req.ip, (err, geoDetails) ->
if geoDetails?.country_code? and geoDetails.country_code != ""
countryCode = geoDetails.country_code
AnalyticsManager.updateEditingSession userId, projectId, countryCode, (error) ->
respondWith(error, res, next)
else
res.send 204
2016-08-10 11:42:56 -04:00
recordEvent: (req, res, next) ->
user_id = AuthenticationController.getLoggedInUserId(req) or req.sessionID
AnalyticsManager.recordEvent user_id, req.params.event, req.body, (error) ->
respondWith(error, res, next)
licences: (req, res, next) ->
{resource_id, start_date, end_date, lag} = req.query
InstitutionsAPI.getInstitutionLicences resource_id, start_date, end_date, lag, (error, licences) ->
if error?
next(error)
else
res.send licences
respondWith = (error, res, next) ->
if error instanceof Errors.ServiceNotConfiguredError
# ignore, no-op
res.send(204)
else if error?
next(error)
else
res.send 204