Просмотр исходного кода

Refactor arguments to MongoManager.getUpdatesBetweenDates

James Allen 12 лет назад
Родитель
Сommit
a46963a349

+ 1 - 1
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)
 	

+ 5 - 0
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
+		
+

+ 5 - 5
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 )

+ 2 - 2
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", ->

+ 5 - 5
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