mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Refactor arguments to MongoManager.getUpdatesBetweenDates
This commit is contained in:
parent
188d620ce1
commit
a46963a349
5 changed files with 18 additions and 13 deletions
|
@ -10,7 +10,7 @@ module.exports = DiffManager =
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
DocumentUpdaterManager.getDocument project_id, doc_id, (error, lines, version) ->
|
DocumentUpdaterManager.getDocument project_id, doc_id, (error, lines, version) ->
|
||||||
return callback(error) if error?
|
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?
|
return callback(error) if error?
|
||||||
callback(null, lines, version, updates)
|
callback(null, lines, version, updates)
|
||||||
|
|
||||||
|
|
|
@ -28,3 +28,8 @@ module.exports = HttpController =
|
||||||
return next(error) if error?
|
return next(error) if error?
|
||||||
res.send JSON.stringify(diff: diff)
|
res.send JSON.stringify(diff: diff)
|
||||||
|
|
||||||
|
getUpdates: (req, res, next = (error) ->) ->
|
||||||
|
doc_id = req.params.doc_id
|
||||||
|
project_id = req.params.project_id
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,13 +39,13 @@ module.exports = MongoManager =
|
||||||
v: update.v
|
v: update.v
|
||||||
}, callback
|
}, callback
|
||||||
|
|
||||||
getUpdatesBetweenDates:(doc_id, fromDate, toDate, callback = (error, updates) ->) ->
|
getUpdatesBetweenDates:(doc_id, options = {}, callback = (error, updates) ->) ->
|
||||||
query =
|
query =
|
||||||
doc_id: ObjectId(doc_id.toString())
|
doc_id: ObjectId(doc_id.toString())
|
||||||
if fromDate?
|
if options.from?
|
||||||
query["meta.start_ts"] = { $gte: fromDate }
|
query["meta.end_ts"] = { $gte: options.from }
|
||||||
if toDate?
|
if options.to?
|
||||||
query["meta.end_ts"] = { $lte: toDate }
|
query["meta.start_ts"] = { $lte: options.to }
|
||||||
db.docHistory
|
db.docHistory
|
||||||
.find( query )
|
.find( query )
|
||||||
.sort( "meta.end_ts": -1 )
|
.sort( "meta.end_ts": -1 )
|
||||||
|
|
|
@ -27,7 +27,7 @@ describe "DiffManager", ->
|
||||||
|
|
||||||
@HistoryManager.processUncompressedUpdatesWithLock = sinon.stub().callsArg(1)
|
@HistoryManager.processUncompressedUpdatesWithLock = sinon.stub().callsArg(1)
|
||||||
@DocumentUpdaterManager.getDocument = sinon.stub().callsArgWith(2, null, @lines, @version)
|
@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
|
@DiffManager.getLatestDocAndUpdates @project_id, @doc_id, @from, @to, @callback
|
||||||
|
|
||||||
it "should ensure the latest updates have been compressed", ->
|
it "should ensure the latest updates have been compressed", ->
|
||||||
|
@ -42,7 +42,7 @@ describe "DiffManager", ->
|
||||||
|
|
||||||
it "should get the requested updates from Mongo", ->
|
it "should get the requested updates from Mongo", ->
|
||||||
@MongoManager.getUpdatesBetweenDates
|
@MongoManager.getUpdatesBetweenDates
|
||||||
.calledWith(@doc_id, @from, @to)
|
.calledWith(@doc_id, from: @from, to: @to)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should call the callback with the lines, version and updates", ->
|
it "should call the callback with the lines, version and updates", ->
|
||||||
|
|
|
@ -145,14 +145,14 @@ describe "MongoManager", ->
|
||||||
|
|
||||||
describe "with a toDate", ->
|
describe "with a toDate", ->
|
||||||
beforeEach ->
|
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", ->
|
it "should find the all updates between the to and from date", ->
|
||||||
@db.docHistory.find
|
@db.docHistory.find
|
||||||
.calledWith({
|
.calledWith({
|
||||||
doc_id: ObjectId(@doc_id)
|
doc_id: ObjectId(@doc_id)
|
||||||
"meta.start_ts": { $gte: @from }
|
"meta.end_ts": { $gte: @from }
|
||||||
"meta.end_ts": { $lte: @to }
|
"meta.start_ts": { $lte: @to }
|
||||||
})
|
})
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
|
@ -166,13 +166,13 @@ describe "MongoManager", ->
|
||||||
|
|
||||||
describe "without a todo date", ->
|
describe "without a todo date", ->
|
||||||
beforeEach ->
|
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", ->
|
it "should find the all updates after the from date", ->
|
||||||
@db.docHistory.find
|
@db.docHistory.find
|
||||||
.calledWith({
|
.calledWith({
|
||||||
doc_id: ObjectId(@doc_id)
|
doc_id: ObjectId(@doc_id)
|
||||||
"meta.start_ts": { $gte: @from }
|
"meta.end_ts": { $gte: @from }
|
||||||
})
|
})
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue