Sfoglia il codice sorgente

Make attributes that can be set in mongo flexible

James Allen 10 anni fa
parent
commit
ca96d168dd

+ 1 - 1
services/docstore/app/coffee/DocArchiveManager.coffee

@@ -67,7 +67,7 @@ module.exports = DocArchive =
 			if err? || res.statusCode != 200
 				logger.err err:err, res:res, project_id:project_id, doc_id:doc_id, "something went wrong unarchiving doc from aws"
 				return callback new Errors.NotFoundError("Error in S3 request")
-			MongoManager.upsertIntoDocCollection project_id, doc_id.toString(), lines, (err) ->
+			MongoManager.upsertIntoDocCollection project_id, doc_id.toString(), {lines}, (err) ->
 				return callback(err) if err?
 				logger.log project_id: project_id, doc_id: doc_id, "deleting doc from s3"
 				request.del options, (err, res, body)->

+ 1 - 1
services/docstore/app/coffee/DocManager.coffee

@@ -67,7 +67,7 @@ module.exports = DocManager =
 					oldVersion: doc?.version
 					newVersion: version
 				}, "updating doc lines"
-				MongoManager.upsertIntoDocCollection project_id, doc_id, lines, (error)->
+				MongoManager.upsertIntoDocCollection project_id, doc_id, {lines}, (error)->
 					return callback(callback) if error?
 					MongoManager.setDocVersion doc_id, version, (error) ->
 						return callback(error) if error?

+ 6 - 8
services/docstore/app/coffee/MongoManager.coffee

@@ -15,18 +15,16 @@ module.exports = MongoManager =
 			inS3: true
 		db.docs.find query, {}, callback
 
-	upsertIntoDocCollection: (project_id, doc_id, lines, callback)->
+	upsertIntoDocCollection: (project_id, doc_id, updates, callback)->
 		update =
-			$set:{}
-			$inc:{}
-			$unset:{}
-		update.$set["lines"] = lines
+			$set: updates
+			$inc:
+				rev: 1
+			$unset:
+				inS3: true
 		update.$set["project_id"] = ObjectId(project_id)
-		update.$inc["rev"] = 1 #on new docs being created this will set the rev to 1
-		update.$unset["inS3"] = true
 		db.docs.update _id: ObjectId(doc_id), update, {upsert: true}, callback
 
-
 	markDocAsDeleted: (project_id, doc_id, callback)->
 		db.docs.update {
 			_id: ObjectId(doc_id),

+ 4 - 4
services/docstore/test/unit/coffee/DocManagerTests.coffee

@@ -179,7 +179,7 @@ describe "DocManager", ->
 
 			it "should upsert the document to the doc collection", ->
 				@MongoManager.upsertIntoDocCollection
-					.calledWith(@project_id, @doc_id, @newDocLines)
+					.calledWith(@project_id, @doc_id, {lines: @newDocLines})
 					.should.equal true
 			
 			it "should update the version", ->
@@ -216,7 +216,7 @@ describe "DocManager", ->
 
 			it "should upsert the document to the doc collection", ->
 				@MongoManager.upsertIntoDocCollection
-					.calledWith(@project_id, @doc_id, @oldDocLines)
+					.calledWith(@project_id, @doc_id, {lines: @oldDocLines})
 					.should.equal true
 			
 			it "should update the version", ->
@@ -272,7 +272,7 @@ describe "DocManager", ->
 
 			it "should upsert the document to the doc collection", ->
 				@MongoManager.upsertIntoDocCollection
-					.calledWith(@project_id, @doc_id,  @doc.lines)
+					.calledWith(@project_id, @doc_id, {lines: @doc.lines})
 					.should.equal true	
 
 		describe "when the doc does not exist", ->
@@ -282,7 +282,7 @@ describe "DocManager", ->
 			
 			it "should upsert the document to the doc collection", ->
 				@MongoManager.upsertIntoDocCollection
-					.calledWith(@project_id, @doc_id, @newDocLines)
+					.calledWith(@project_id, @doc_id, {lines: @newDocLines})
 					.should.equal true
 
 			it "should return the callback with the new rev", ->

+ 2 - 2
services/docstore/test/unit/coffee/MongoManagerTests.coffee

@@ -58,7 +58,7 @@ describe "MongoManager", ->
 			@oldRev = 77
 
 		it "should upsert the document", (done)->	
-			@MongoManager.upsertIntoDocCollection @project_id, @doc_id, @lines, (err)=>
+			@MongoManager.upsertIntoDocCollection @project_id, @doc_id, {@lines}, (err)=>
 				args = @db.docs.update.args[0]
 				assert.deepEqual args[0], {_id: ObjectId(@doc_id)}
 				assert.equal args[1]["$set"]["lines"], @lines
@@ -67,7 +67,7 @@ describe "MongoManager", ->
 				done()
 
 		it "should return the error", (done)->
-			@MongoManager.upsertIntoDocCollection @project_id, @doc_id, @lines, (err)=>
+			@MongoManager.upsertIntoDocCollection @project_id, @doc_id, {@lines}, (err)=>
 				err.should.equal @stubbedErr
 				done()