|
@@ -537,10 +537,9 @@ module.exports = {
|
|
|
callback(req, res, 1, err, null);
|
|
|
}
|
|
|
},
|
|
|
- //接收到的分享项目,返回未定义组、已定义组
|
|
|
receiveProjects: async function(req, res) {
|
|
|
try {
|
|
|
- let rst = {grouped: [], ungrouped: []}
|
|
|
+ let rst = {grouped: [], ungrouped: []};
|
|
|
let userID = req.session.sessionUser.id;
|
|
|
let receiveProjects = await projectModel.find({
|
|
|
$or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], compilation: req.session.sessionCompilation._id, 'shareInfo.userID': userID}, '-_id -property');
|
|
@@ -583,71 +582,6 @@ module.exports = {
|
|
|
callback(req, res, 1, err, null);
|
|
|
}
|
|
|
},
|
|
|
- getShareProjects: async function (req, res) {
|
|
|
- try {
|
|
|
- let userID = req.session.sessionUser.id;
|
|
|
- let rst = {receive: [], share: []}//接收的、由我分享的
|
|
|
- let shareProjects = await projectModel.find({userID: userID,
|
|
|
- $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], compilation: req.session.sessionCompilation._id, 'shareInfo.0': {$exists: true}});
|
|
|
- //项目类型为分享给别人
|
|
|
- let shareToUserIDs = [];
|
|
|
- for(let proj of shareProjects){
|
|
|
- proj._doc.shareType = 'shareTo';
|
|
|
- for(let shareToUser of proj.shareInfo){
|
|
|
- shareToUserIDs.push(shareToUser.userID);
|
|
|
- }
|
|
|
- }
|
|
|
- shareToUserIDs = Array.from(new Set(shareToUserIDs));
|
|
|
- let shareToObjIDs = [];
|
|
|
- for(let userID of shareToUserIDs){
|
|
|
- shareToObjIDs.push(mongoose.Types.ObjectId(userID));
|
|
|
- }
|
|
|
- let shareToUsers = await userModel.find({_id: {$in: shareToObjIDs}});
|
|
|
- for(let shareToUser of shareToUsers){
|
|
|
- for(let proj of shareProjects){
|
|
|
- for(let user of proj.shareInfo){
|
|
|
- if(user.userID === shareToUser._id.toString()){
|
|
|
- user._doc.company = shareToUser.company;
|
|
|
- user._doc.email = shareToUser.email;
|
|
|
- user._doc.name = shareToUser.real_name;
|
|
|
- user._doc.mobile = shareToUser.mobile;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- rst.share = shareProjects;
|
|
|
- let receiveProjects = await projectModel.find({
|
|
|
- $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], compilation: req.session.sessionCompilation._id, 'shareInfo.userID': userID});
|
|
|
- //设置原项目用户信息
|
|
|
- if(receiveProjects.length > 0){
|
|
|
- let orgUserIDs = [];
|
|
|
- for(let proj of receiveProjects){
|
|
|
- orgUserIDs.push(proj.userID);
|
|
|
- }
|
|
|
- orgUserIDs = Array.from(new Set(orgUserIDs));
|
|
|
- let userObjIDs = [];
|
|
|
- for(let uID of orgUserIDs){
|
|
|
- userObjIDs.push(mongoose.Types.ObjectId(uID));
|
|
|
- }
|
|
|
- let orgUsersInfo = await userModel.find({_id: {$in : userObjIDs}});
|
|
|
- for(let proj of receiveProjects){
|
|
|
- //设置项目类型为来自别人分享
|
|
|
- proj._doc.shareType = 'receive';
|
|
|
- for(let userData of orgUsersInfo){
|
|
|
- if(proj.userID == userData._id.toString()){
|
|
|
- let userInfo = {name: userData.real_name, mobile: userData.mobile, company: userData.company, email: userData.email};
|
|
|
- proj._doc.userInfo = userInfo;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- rst.receive = receiveProjects;
|
|
|
- callback(req, res, 0, 'success', rst);
|
|
|
- }
|
|
|
- catch (err){
|
|
|
- callback(req, res, 1, err, null);
|
|
|
- }
|
|
|
- },
|
|
|
getProjectsByQuery: async function (req, res) {
|
|
|
try{
|
|
|
let data = JSON.parse(req.body.data);
|