2014-04-28 15:45:59 +00:00
|
|
|
{db, ObjectId} = require "./mongojs"
|
|
|
|
|
|
|
|
module.exports = MongoManager =
|
2014-04-28 16:43:19 +00:00
|
|
|
|
2014-06-05 12:29:50 +00:00
|
|
|
findDoc: (doc_id, callback = (error, doc) ->) ->
|
|
|
|
db.docs.find _id: ObjectId(doc_id.toString()), {}, (error, docs = []) ->
|
|
|
|
callback error, docs[0]
|
|
|
|
|
2015-02-20 14:28:16 +00:00
|
|
|
getProjectsDocs: (project_id, callback)->
|
|
|
|
db.docs.find project_id: ObjectId(project_id.toString()), {}, callback
|
2014-04-29 14:07:22 +00:00
|
|
|
|
2015-06-02 18:55:22 +00:00
|
|
|
getArchivedProjectDocs: (project_id, callback)->
|
|
|
|
query =
|
|
|
|
project_id: ObjectId(project_id.toString())
|
|
|
|
inS3: true
|
|
|
|
db.docs.find query, {}, callback
|
|
|
|
|
2015-02-27 14:06:06 +00:00
|
|
|
upsertIntoDocCollection: (project_id, doc_id, lines, callback)->
|
2015-01-20 17:09:51 +00:00
|
|
|
update =
|
|
|
|
$set:{}
|
2015-02-26 16:01:10 +00:00
|
|
|
$inc:{}
|
2015-06-01 22:36:26 +00:00
|
|
|
$unset:{}
|
2015-01-20 17:09:51 +00:00
|
|
|
update.$set["lines"] = lines
|
|
|
|
update.$set["project_id"] = ObjectId(project_id)
|
2015-02-26 16:01:10 +00:00
|
|
|
update.$inc["rev"] = 1 #on new docs being created this will set the rev to 1
|
2015-06-01 22:36:26 +00:00
|
|
|
update.$unset["inS3"] = true
|
2015-01-20 17:09:51 +00:00
|
|
|
db.docs.update _id: ObjectId(doc_id), update, {upsert: true}, callback
|
|
|
|
|
|
|
|
|
|
|
|
markDocAsDeleted: (doc_id, callback)->
|
|
|
|
update =
|
|
|
|
$set: {}
|
|
|
|
update.$set["deleted"] = true
|
|
|
|
db.docs.update _id: ObjectId(doc_id), update, (err)->
|
|
|
|
callback(err)
|
2015-06-01 22:36:26 +00:00
|
|
|
|
2015-06-02 11:39:49 +00:00
|
|
|
markDocAsArchived: (doc_id, rev, callback)->
|
2015-06-01 22:36:26 +00:00
|
|
|
update =
|
|
|
|
$set: {}
|
|
|
|
$unset: {}
|
|
|
|
update.$set["inS3"] = true
|
|
|
|
update.$unset["lines"] = true
|
2015-06-02 18:55:22 +00:00
|
|
|
query =
|
|
|
|
_id: doc_id
|
|
|
|
rev: rev
|
|
|
|
db.docs.update query, update, (err)->
|
2015-06-01 22:36:26 +00:00
|
|
|
callback(err)
|