- Modified privacywrite query with graphLookup:
$graphLookup: {
from: "projects",
startWith: "$id_main_project",
connectFromField: "id_main_project",
connectToField: "_id",
as: "ris",
restrictSearchWithMatch: { $or: [{ privacyread: server_constants.Privacy.all }, { userId: userId }] }
}
},
{ $match: { "ris.privacyread": { $exists: true } } },
This commit is contained in:
@@ -32,12 +32,8 @@ var ProjectSchema = new mongoose.Schema({
|
||||
typeproj: {
|
||||
type: Number,
|
||||
},
|
||||
id_main_project: {
|
||||
type: String,
|
||||
},
|
||||
id_parent: {
|
||||
type: String,
|
||||
},
|
||||
id_main_project: mongoose.Schema.Types.ObjectId,
|
||||
id_parent: mongoose.Schema.Types.ObjectId,
|
||||
priority: {
|
||||
type: Number,
|
||||
},
|
||||
@@ -61,9 +57,7 @@ var ProjectSchema = new mongoose.Schema({
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
id_prev: {
|
||||
type: String,
|
||||
},
|
||||
id_prev: mongoose.Schema.Types.ObjectId,
|
||||
modified: {
|
||||
type: Boolean,
|
||||
},
|
||||
@@ -156,18 +150,47 @@ ProjectSchema.statics.findProjectByUserId = function (userId, idproj) {
|
||||
};
|
||||
|
||||
|
||||
ProjectSchema.statics.findAllByUserId = function (userId) {
|
||||
ProjectSchema.statics.findAllProjByUserId = async function (userId) {
|
||||
var Project = this;
|
||||
|
||||
return Project.find({ 'typeproj': server_constants.TypeProj.TYPE_PROJECT,
|
||||
$or: [
|
||||
{ 'userId': userId },
|
||||
{'privacyread' : server_constants.Privacy.all}
|
||||
]
|
||||
}).then(ris => {
|
||||
return ris
|
||||
return Project.aggregate([
|
||||
{
|
||||
$graphLookup: {
|
||||
from: "projects",
|
||||
startWith: "$id_main_project",
|
||||
connectFromField: "id_main_project",
|
||||
connectToField: "_id",
|
||||
as: "ris",
|
||||
restrictSearchWithMatch: { $or: [{ privacyread: server_constants.Privacy.all }, { userId: userId }] }
|
||||
}
|
||||
},
|
||||
{ $match: { "ris.privacyread": { $exists: true } } },
|
||||
|
||||
// {
|
||||
// $project: {
|
||||
// "descr": 1,
|
||||
// "typeproj": 1,
|
||||
// "id_main_project": 1,
|
||||
// }
|
||||
// }
|
||||
]).then(ris1 => {
|
||||
|
||||
console.log('findAllProjByUserId', ris1);
|
||||
|
||||
return ris1;
|
||||
})
|
||||
|
||||
// return Project.find({
|
||||
// $or: [
|
||||
// { 'userId': userId },
|
||||
// {'privacyread' : server_constants.Privacy.all}
|
||||
// ],
|
||||
// $or: [
|
||||
// { 'typeproj': server_constants.TypeProj.TYPE_PROJECT },
|
||||
// { 'typeproj': server_constants.TypeProj.TYPE_SUBDIR }
|
||||
// ],
|
||||
|
||||
|
||||
};
|
||||
|
||||
ProjectSchema.statics.getArrIdParentInTable = function (userId) {
|
||||
@@ -197,15 +220,44 @@ ProjectSchema.statics.getIdParentByIdProj = function (idProj) {
|
||||
|
||||
ProjectSchema.statics.getAllProjects = async function (userId) {
|
||||
var Project = this;
|
||||
console.log('getAllProjects');
|
||||
|
||||
let obj = [];
|
||||
|
||||
obj.arrproj = await Project.findAllByUserId(userId);
|
||||
const projbase = await Project.findById(process.env.PROJECT_ID_MAIN)
|
||||
.then(ris => {
|
||||
console.log('ris', ris);
|
||||
if (!!ris._doc)
|
||||
return ris._doc;
|
||||
else
|
||||
return null;
|
||||
});
|
||||
|
||||
obj.arrproj = await Project.findAllProjByUserId(userId);
|
||||
obj.arrproj.push(projbase);
|
||||
|
||||
return obj;
|
||||
|
||||
};
|
||||
|
||||
ProjectSchema.statics.enabletoModify = async function (userId, idProj) {
|
||||
var Project = this;
|
||||
console.log('getAllProjects');
|
||||
|
||||
let obj = [];
|
||||
|
||||
return Project.findOne({
|
||||
'_id': idProj,
|
||||
$or: [{
|
||||
'privacywrite': server_constants.Privacy.all,
|
||||
'userId': userId
|
||||
}]
|
||||
}).then(ris => {
|
||||
return (!!ris);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
ProjectSchema.statics.updateCalc = async function (userId, idproj, objdatacalc, recIn) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
@@ -55,9 +55,7 @@ var TodoSchema = new mongoose.Schema({
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
id_prev: {
|
||||
type: String,
|
||||
},
|
||||
id_prev: mongoose.Schema.Types.ObjectId,
|
||||
progress: {
|
||||
type: Number,
|
||||
},
|
||||
@@ -148,8 +146,10 @@ TodoSchema.statics.getAllTodo = async function (userId) {
|
||||
|
||||
const arrtodos = [];
|
||||
if (obj.arrcategories.length > 0) {
|
||||
for (let mycat in obj.arrcategories) {
|
||||
arrtodos.push(tools.mapSort(arralltodo.filter(item => item.category === obj.arrcategories[mycat])))
|
||||
for (const mycat of obj.arrcategories) {
|
||||
const arrfiltrato = arralltodo.filter(item => item.category === mycat);
|
||||
// console.log('arrfiltrato ', mycat, arrfiltrato);
|
||||
arrtodos.push(tools.mapSort(arrfiltrato))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user