2018-12-04 06:19:48 -05:00
|
|
|
ObjectId = require("mongojs").ObjectId
|
2018-11-14 09:42:21 -05:00
|
|
|
Project = require("../../models/Project").Project
|
|
|
|
|
|
|
|
module.exports = ProjectCollabratecDetailsHandler =
|
2018-12-04 06:19:48 -05:00
|
|
|
initializeCollabratecProject: (project_id, user_id, collabratec_document_id, collabratec_privategroup_id, callback=(err)->) ->
|
|
|
|
try
|
|
|
|
project_id = ObjectId(project_id)
|
|
|
|
user_id = ObjectId(user_id)
|
|
|
|
catch err
|
|
|
|
return callback err
|
|
|
|
update = $set: { collabratecUsers: [ { user_id, collabratec_document_id, collabratec_privategroup_id } ] }
|
2018-11-14 09:42:21 -05:00
|
|
|
Project.update { _id: project_id }, update, callback
|
2018-12-04 06:19:48 -05:00
|
|
|
|
|
|
|
isLinkedCollabratecUserProject: (project_id, user_id, callback=(err, isLinked)->) ->
|
|
|
|
try
|
|
|
|
project_id = ObjectId(project_id)
|
|
|
|
user_id = ObjectId(user_id)
|
|
|
|
catch err
|
|
|
|
return callback err
|
|
|
|
query =
|
|
|
|
_id: project_id
|
|
|
|
collabratecUsers: $elemMatch:
|
|
|
|
user_id: user_id
|
|
|
|
Project.findOne query, {_id: 1}, (err, project) ->
|
|
|
|
callback err if err?
|
|
|
|
callback null, project?
|
|
|
|
|
|
|
|
linkCollabratecUserProject: (project_id, user_id, collabratec_document_id, callback=(err)->) ->
|
|
|
|
try
|
|
|
|
project_id = ObjectId(project_id)
|
|
|
|
user_id = ObjectId(user_id)
|
|
|
|
catch err
|
|
|
|
return callback err
|
|
|
|
query =
|
|
|
|
_id: project_id
|
|
|
|
collabratecUsers: $not: $elemMatch:
|
|
|
|
collabratec_document_id: collabratec_document_id
|
|
|
|
user_id: user_id
|
|
|
|
update = $push: collabratecUsers:
|
|
|
|
collabratec_document_id: collabratec_document_id
|
|
|
|
user_id: user_id
|
|
|
|
Project.update query, update, callback
|
|
|
|
|
|
|
|
unlinkCollabratecUserProject: (project_id, user_id, callback=(err)->) ->
|
|
|
|
try
|
|
|
|
project_id = ObjectId(project_id)
|
|
|
|
user_id = ObjectId(user_id)
|
|
|
|
catch err
|
|
|
|
return callback err
|
|
|
|
query =
|
|
|
|
_id: project_id
|
|
|
|
update = $pull: collabratecUsers:
|
|
|
|
user_id: user_id
|
|
|
|
Project.update query, update, callback
|