mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 14:43:46 +01:00
Make attributes that can be set in mongo flexible
This commit is contained in:
@@ -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()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user