Make attributes that can be set in mongo flexible

This commit is contained in:
James Allen
2016-12-02 15:22:08 +00:00
parent 144bae3a55
commit ca96d168dd
5 changed files with 14 additions and 16 deletions
@@ -67,7 +67,7 @@ module.exports = DocArchive =
if err? || res.statusCode != 200 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" 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") 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? return callback(err) if err?
logger.log project_id: project_id, doc_id: doc_id, "deleting doc from s3" logger.log project_id: project_id, doc_id: doc_id, "deleting doc from s3"
request.del options, (err, res, body)-> request.del options, (err, res, body)->
@@ -67,7 +67,7 @@ module.exports = DocManager =
oldVersion: doc?.version oldVersion: doc?.version
newVersion: version newVersion: version
}, "updating doc lines" }, "updating doc lines"
MongoManager.upsertIntoDocCollection project_id, doc_id, lines, (error)-> MongoManager.upsertIntoDocCollection project_id, doc_id, {lines}, (error)->
return callback(callback) if error? return callback(callback) if error?
MongoManager.setDocVersion doc_id, version, (error) -> MongoManager.setDocVersion doc_id, version, (error) ->
return callback(error) if error? return callback(error) if error?
@@ -15,18 +15,16 @@ module.exports = MongoManager =
inS3: true inS3: true
db.docs.find query, {}, callback db.docs.find query, {}, callback
upsertIntoDocCollection: (project_id, doc_id, lines, callback)-> upsertIntoDocCollection: (project_id, doc_id, updates, callback)->
update = update =
$set:{} $set: updates
$inc:{} $inc:
$unset:{} rev: 1
update.$set["lines"] = lines $unset:
inS3: true
update.$set["project_id"] = ObjectId(project_id) 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 db.docs.update _id: ObjectId(doc_id), update, {upsert: true}, callback
markDocAsDeleted: (project_id, doc_id, callback)-> markDocAsDeleted: (project_id, doc_id, callback)->
db.docs.update { db.docs.update {
_id: ObjectId(doc_id), _id: ObjectId(doc_id),
@@ -179,7 +179,7 @@ describe "DocManager", ->
it "should upsert the document to the doc collection", -> it "should upsert the document to the doc collection", ->
@MongoManager.upsertIntoDocCollection @MongoManager.upsertIntoDocCollection
.calledWith(@project_id, @doc_id, @newDocLines) .calledWith(@project_id, @doc_id, {lines: @newDocLines})
.should.equal true .should.equal true
it "should update the version", -> it "should update the version", ->
@@ -216,7 +216,7 @@ describe "DocManager", ->
it "should upsert the document to the doc collection", -> it "should upsert the document to the doc collection", ->
@MongoManager.upsertIntoDocCollection @MongoManager.upsertIntoDocCollection
.calledWith(@project_id, @doc_id, @oldDocLines) .calledWith(@project_id, @doc_id, {lines: @oldDocLines})
.should.equal true .should.equal true
it "should update the version", -> it "should update the version", ->
@@ -272,7 +272,7 @@ describe "DocManager", ->
it "should upsert the document to the doc collection", -> it "should upsert the document to the doc collection", ->
@MongoManager.upsertIntoDocCollection @MongoManager.upsertIntoDocCollection
.calledWith(@project_id, @doc_id, @doc.lines) .calledWith(@project_id, @doc_id, {lines: @doc.lines})
.should.equal true .should.equal true
describe "when the doc does not exist", -> describe "when the doc does not exist", ->
@@ -282,7 +282,7 @@ describe "DocManager", ->
it "should upsert the document to the doc collection", -> it "should upsert the document to the doc collection", ->
@MongoManager.upsertIntoDocCollection @MongoManager.upsertIntoDocCollection
.calledWith(@project_id, @doc_id, @newDocLines) .calledWith(@project_id, @doc_id, {lines: @newDocLines})
.should.equal true .should.equal true
it "should return the callback with the new rev", -> it "should return the callback with the new rev", ->
@@ -58,7 +58,7 @@ describe "MongoManager", ->
@oldRev = 77 @oldRev = 77
it "should upsert the document", (done)-> 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] args = @db.docs.update.args[0]
assert.deepEqual args[0], {_id: ObjectId(@doc_id)} assert.deepEqual args[0], {_id: ObjectId(@doc_id)}
assert.equal args[1]["$set"]["lines"], @lines assert.equal args[1]["$set"]["lines"], @lines
@@ -67,7 +67,7 @@ describe "MongoManager", ->
done() done()
it "should return the error", (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 err.should.equal @stubbedErr
done() done()