2014-04-29 06:49:09 -04:00
|
|
|
request = require("request").defaults(jar: false)
|
|
|
|
{db, ObjectId} = require("../../../../app/js/mongojs")
|
|
|
|
|
|
|
|
module.exports = DocstoreClient =
|
2014-04-30 08:06:12 -04:00
|
|
|
createProject: (project_id, callback = (error) ->) ->
|
2014-04-29 06:49:09 -04:00
|
|
|
db.projects.insert {
|
|
|
|
_id: project_id
|
2014-04-30 08:06:12 -04:00
|
|
|
rootFolder: [{ docs: [] }]
|
|
|
|
}, callback
|
|
|
|
|
2014-05-08 10:43:08 -04:00
|
|
|
createDoc: (project_id, doc_id, lines, version, callback = (error) ->) ->
|
2014-04-30 08:06:12 -04:00
|
|
|
db.projects.update {
|
|
|
|
_id: project_id
|
|
|
|
}, {
|
|
|
|
$push: {
|
|
|
|
"rootFolder.0.docs": {
|
|
|
|
_id: doc_id
|
2014-04-29 06:49:09 -04:00
|
|
|
lines: lines
|
2014-05-08 10:43:08 -04:00
|
|
|
version: version
|
2014-04-30 08:06:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}, callback
|
2014-04-29 06:49:09 -04:00
|
|
|
|
|
|
|
deleteProject: (project_id, callback = (error, res, body) ->) ->
|
|
|
|
db.projects.remove _id: project_id, callback
|
|
|
|
|
2014-04-30 08:06:12 -04:00
|
|
|
getDoc: (project_id, doc_id, callback = (error, res, body) ->) ->
|
2014-04-29 06:49:09 -04:00
|
|
|
request.get {
|
|
|
|
url: "http://localhost:3016/project/#{project_id}/doc/#{doc_id}"
|
|
|
|
json: true
|
|
|
|
}, callback
|
|
|
|
|
2014-04-30 08:06:12 -04:00
|
|
|
getAllDocs: (project_id, callback = (error, res, body) ->) ->
|
|
|
|
request.get {
|
|
|
|
url: "http://localhost:3016/project/#{project_id}/doc"
|
|
|
|
json: true
|
|
|
|
}, callback
|
|
|
|
|
2014-05-08 10:43:08 -04:00
|
|
|
updateDoc: (project_id, doc_id, lines, version, callback = (error, res, body) ->) ->
|
2014-04-29 06:49:09 -04:00
|
|
|
request.post {
|
|
|
|
url: "http://localhost:3016/project/#{project_id}/doc/#{doc_id}"
|
|
|
|
json:
|
|
|
|
lines: lines
|
2014-05-08 10:43:08 -04:00
|
|
|
version: version
|
2014-04-29 06:49:09 -04:00
|
|
|
}, callback
|
2014-04-29 11:36:10 -04:00
|
|
|
|
|
|
|
deleteDoc: (project_id, doc_id, callback = (error, res, body) ->) ->
|
|
|
|
request.del {
|
|
|
|
url: "http://localhost:3016/project/#{project_id}/doc/#{doc_id}"
|
|
|
|
}, callback
|
2014-04-29 06:49:09 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|