Merge pull request #10 from sharelatex/ho-delete-dict

added delete dic endpoint
This commit is contained in:
Henry Oswald 2017-11-02 11:14:03 +00:00 committed by GitHub
commit 748b285e47
5 changed files with 24 additions and 1 deletions

View file

@ -19,6 +19,7 @@ HealthCheckController = require("./app/js/HealthCheckController")
server.use bodyParser.json(limit: "2mb")
server.use metrics.http.monitor(logger)
server.del "/user/:user_id", SpellingAPIController.deleteDic
server.post "/user/:user_id/check", SpellingAPIController.check
server.post "/user/:user_id/learn", SpellingAPIController.learn
server.get "/status", (req, res)->

View file

@ -29,6 +29,9 @@ module.exports = LearnedWordsManager =
mongoCache.set(user_token, words)
callback null, words
deleteUsersLearnedWords: (user_token, callback =(error)->)->
db.spellingPreferences.remove token: user_token, callback
[
'learnWord',

View file

@ -21,3 +21,9 @@ module.exports = SpellingAPIController =
next()
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)

View file

@ -46,4 +46,6 @@ module.exports = SpellingAPIManager =
LearnedWordsManager.learnWord token, request.word, callback
deleteDic: (token, callback)->
LearnedWordsManager.deleteUsersLearnedWords token, callback

View file

@ -84,3 +84,14 @@ describe "LearnedWordsManager", ->
@cache.del.calledWith(@token).should.equal true
done()
describe "deleteUsersLearnedWords", ->
beforeEach ->
@db.spellingPreferences.delete = sinon.stub().callsArgWith(1)
it "should get the word list for the given user", (done)->
@LearnedWordsManager.deleteUsersLearnedWords @token, =>
@db.spellingPreferences.delete.calledWith(token: @token).should.equal true
done()