2014-08-15 07:13:35 -04:00
|
|
|
SpellingAPIManager = require './SpellingAPIManager'
|
|
|
|
logger = require 'logger-sharelatex'
|
2015-03-02 13:13:28 -05:00
|
|
|
metrics = require('metrics-sharelatex')
|
2014-08-15 07:13:35 -04:00
|
|
|
|
|
|
|
module.exports = SpellingAPIController =
|
|
|
|
check: (req, res, next) ->
|
|
|
|
metrics.inc "spelling-check", 0.1
|
2015-03-03 03:10:47 -05:00
|
|
|
logger.log token: req?.params?.user_id, word_count: req?.body?.words?.length, "running check"
|
|
|
|
SpellingAPIManager.runRequest req.params.user_id, req.body, (error, result) ->
|
2015-03-09 11:52:25 -04:00
|
|
|
if error?
|
|
|
|
logger.err err:error, user_id:req?.params?.user_id, word_count: req?.body?.words?.length, "error processing spelling request"
|
2015-03-03 03:10:47 -05:00
|
|
|
return res.send(500)
|
|
|
|
res.send(result)
|
2014-08-15 07:13:35 -04:00
|
|
|
|
|
|
|
learn: (req, res, next) ->
|
|
|
|
metrics.inc "spelling-learn", 0.1
|
2015-03-03 03:10:47 -05:00
|
|
|
logger.log token: req?.params?.user_id, word: req?.body?.word, "learning word"
|
|
|
|
SpellingAPIManager.learnWord req.params.user_id, req.body, (error, result) ->
|
|
|
|
return next(error) if error?
|
2015-03-03 10:20:05 -05:00
|
|
|
res.sendStatus(200)
|
2015-03-03 03:10:47 -05:00
|
|
|
next()
|
2014-08-15 07:13:35 -04:00
|
|
|
|
|
|
|
|