diff --git a/services/track-changes/app/coffee/DiffManager.coffee b/services/track-changes/app/coffee/DiffManager.coffee index eddb461c53..ab6ea41b4b 100644 --- a/services/track-changes/app/coffee/DiffManager.coffee +++ b/services/track-changes/app/coffee/DiffManager.coffee @@ -10,7 +10,7 @@ module.exports = DiffManager = return callback(error) if error? DocumentUpdaterManager.getDocument project_id, doc_id, (error, lines, version) -> return callback(error) if error? - MongoManager.getUpdatesBetweenDates doc_id, fromDate, toDate, (error, updates) -> + MongoManager.getUpdatesBetweenDates doc_id, from: fromDate, to: toDate, (error, updates) -> return callback(error) if error? callback(null, lines, version, updates) diff --git a/services/track-changes/app/coffee/HttpController.coffee b/services/track-changes/app/coffee/HttpController.coffee index 5b742e8891..b33eea596e 100644 --- a/services/track-changes/app/coffee/HttpController.coffee +++ b/services/track-changes/app/coffee/HttpController.coffee @@ -28,3 +28,8 @@ module.exports = HttpController = return next(error) if error? res.send JSON.stringify(diff: diff) + getUpdates: (req, res, next = (error) ->) -> + doc_id = req.params.doc_id + project_id = req.params.project_id + + diff --git a/services/track-changes/app/coffee/MongoManager.coffee b/services/track-changes/app/coffee/MongoManager.coffee index 1f884d0b67..6a9f10fe73 100644 --- a/services/track-changes/app/coffee/MongoManager.coffee +++ b/services/track-changes/app/coffee/MongoManager.coffee @@ -39,13 +39,13 @@ module.exports = MongoManager = v: update.v }, callback - getUpdatesBetweenDates:(doc_id, fromDate, toDate, callback = (error, updates) ->) -> + getUpdatesBetweenDates:(doc_id, options = {}, callback = (error, updates) ->) -> query = doc_id: ObjectId(doc_id.toString()) - if fromDate? - query["meta.start_ts"] = { $gte: fromDate } - if toDate? - query["meta.end_ts"] = { $lte: toDate } + if options.from? + query["meta.end_ts"] = { $gte: options.from } + if options.to? + query["meta.start_ts"] = { $lte: options.to } db.docHistory .find( query ) .sort( "meta.end_ts": -1 ) diff --git a/services/track-changes/test/unit/coffee/DiffManager/DiffManagerTests.coffee b/services/track-changes/test/unit/coffee/DiffManager/DiffManagerTests.coffee index 391ad138cb..b057425ff5 100644 --- a/services/track-changes/test/unit/coffee/DiffManager/DiffManagerTests.coffee +++ b/services/track-changes/test/unit/coffee/DiffManager/DiffManagerTests.coffee @@ -27,7 +27,7 @@ describe "DiffManager", -> @HistoryManager.processUncompressedUpdatesWithLock = sinon.stub().callsArg(1) @DocumentUpdaterManager.getDocument = sinon.stub().callsArgWith(2, null, @lines, @version) - @MongoManager.getUpdatesBetweenDates = sinon.stub().callsArgWith(3, null, @updates) + @MongoManager.getUpdatesBetweenDates = sinon.stub().callsArgWith(2, null, @updates) @DiffManager.getLatestDocAndUpdates @project_id, @doc_id, @from, @to, @callback it "should ensure the latest updates have been compressed", -> @@ -42,7 +42,7 @@ describe "DiffManager", -> it "should get the requested updates from Mongo", -> @MongoManager.getUpdatesBetweenDates - .calledWith(@doc_id, @from, @to) + .calledWith(@doc_id, from: @from, to: @to) .should.equal true it "should call the callback with the lines, version and updates", -> diff --git a/services/track-changes/test/unit/coffee/MongoManager/MongoManagerTests.coffee b/services/track-changes/test/unit/coffee/MongoManager/MongoManagerTests.coffee index 21f57c6477..9a0d83169a 100644 --- a/services/track-changes/test/unit/coffee/MongoManager/MongoManagerTests.coffee +++ b/services/track-changes/test/unit/coffee/MongoManager/MongoManagerTests.coffee @@ -145,14 +145,14 @@ describe "MongoManager", -> describe "with a toDate", -> beforeEach -> - @MongoManager.getUpdatesBetweenDates @doc_id, @from, @to, @callback + @MongoManager.getUpdatesBetweenDates @doc_id, from: @from, to: @to, @callback it "should find the all updates between the to and from date", -> @db.docHistory.find .calledWith({ doc_id: ObjectId(@doc_id) - "meta.start_ts": { $gte: @from } - "meta.end_ts": { $lte: @to } + "meta.end_ts": { $gte: @from } + "meta.start_ts": { $lte: @to } }) .should.equal true @@ -166,13 +166,13 @@ describe "MongoManager", -> describe "without a todo date", -> beforeEach -> - @MongoManager.getUpdatesBetweenDates @doc_id, @from, null, @callback + @MongoManager.getUpdatesBetweenDates @doc_id, from: @from, @callback it "should find the all updates after the from date", -> @db.docHistory.find .calledWith({ doc_id: ObjectId(@doc_id) - "meta.start_ts": { $gte: @from } + "meta.end_ts": { $gte: @from } }) .should.equal true