overleaf/services/spelling/app/coffee/SpellingAPIController.coffee

35 lines
1.3 KiB
CoffeeScript
Raw Normal View History

2014-08-15 11:13:35 +00:00
SpellingAPIManager = require './SpellingAPIManager'
logger = require 'logger-sharelatex'
metrics = require('metrics-sharelatex')
2014-08-15 11:13:35 +00:00
module.exports = SpellingAPIController =
check: (req, res, next) ->
metrics.inc "spelling-check", 0.1
2019-01-09 15:37:03 +00:00
logger.info token: req?.params?.user_id, word_count: req?.body?.words?.length, "running check"
2015-03-03 08:10:47 +00:00
SpellingAPIManager.runRequest req.params.user_id, req.body, (error, result) ->
2015-03-09 15:52:25 +00:00
if error?
logger.err err:error, user_id:req?.params?.user_id, word_count: req?.body?.words?.length, "error processing spelling request"
return res.sendStatus(500)
2016-03-01 13:22:51 +00:00
res.send(result)
2014-08-15 11:13:35 +00:00
learn: (req, res, next) ->
metrics.inc "spelling-learn", 0.1
2019-01-09 15:37:03 +00:00
logger.info token: req?.params?.user_id, word: req?.body?.word, "learning word"
2015-03-03 08:10:47 +00:00
SpellingAPIManager.learnWord req.params.user_id, req.body, (error, result) ->
return next(error) if error?
2015-03-03 15:20:05 +00:00
res.sendStatus(200)
2015-03-03 08:10:47 +00:00
next()
2014-08-15 11:13:35 +00:00
2017-10-30 16:57:34 +00:00
deleteDic: (req, res, next)->
logger.log token: req?.params?.user_id, word: req?.body?.word, "deleting user dictionary"
SpellingAPIManager.deleteDic req.params.user_id, (error) ->
return next(error) if error?
res.sendStatus(204)
2019-01-02 14:46:44 +00:00
getDic: (req, res, next)->
logger.info token: req?.params?.user_id, "getting user dictionary"
SpellingAPIManager.getDic req.params.user_id, (error, words)->
return next(error) if error?
res.send(words)