- 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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,13 +70,16 @@ router.patch('/:id', authenticate, (req, res) => {
|
||||
var id = req.params.id;
|
||||
var body = _.pick(req.body, tools.allfieldProject());
|
||||
|
||||
tools.mylogshow('PATCH PROJECT: ', id)
|
||||
tools.mylogshow('PATCH PROJECT: ', id);
|
||||
|
||||
if (!ObjectID.isValid(id)) {
|
||||
tools.mylog('ERROR: id not VALID', id);
|
||||
return res.status(404).send();
|
||||
}
|
||||
|
||||
// check if you are able to modify this project
|
||||
if (!Project.enabletoModify(String(req.user._id), id))
|
||||
return res.status(404).send();
|
||||
|
||||
Project.findByIdAndUpdate(id, { $set: body }, { new: true }).then((project) => {
|
||||
tools.mylogshow(' PROJECT TO MODIFY: ', project.descr);
|
||||
@@ -128,7 +131,8 @@ router.get('/:userId', authenticate, (req, res) => {
|
||||
// Extract all the projects of the userId only
|
||||
// Project.findAllByUserIdAndCat(userId, category).then((projects) => {
|
||||
return Project.getAllProjects(userId).then((objprojects) => {
|
||||
tools.mylog('projects', objprojects.arrproj.length);
|
||||
if (!!objprojects.arrproj)
|
||||
tools.mylog('projects', objprojects.arrproj.length);
|
||||
|
||||
return objprojects
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ const todos = [{
|
||||
descr: "Primo Task Esempio",
|
||||
enableExpiring: false,
|
||||
expiring_at: new Date(),
|
||||
id_prev: "0",
|
||||
id_prev: null,
|
||||
modified: false,
|
||||
modify_at: new Date(),
|
||||
pos: 1,
|
||||
@@ -97,7 +97,7 @@ const todos = [{
|
||||
descr: "Secondo Task Esempio",
|
||||
enableExpiring: false,
|
||||
expiring_at: new Date(),
|
||||
id_prev: "1",
|
||||
// id_prev: "1",
|
||||
modified: false,
|
||||
modify_at: new Date(),
|
||||
pos: 2,
|
||||
@@ -113,7 +113,7 @@ const todos = [{
|
||||
descr: "Terzo Task Esempio",
|
||||
enableExpiring: false,
|
||||
expiring_at: new Date(),
|
||||
id_prev: "1",
|
||||
// id_prev: "1",
|
||||
modified: false,
|
||||
modify_at: new Date(),
|
||||
pos: 3,
|
||||
@@ -129,7 +129,7 @@ const todos = [{
|
||||
descr: "Nuovo Quarto Task Esempio da Inserire",
|
||||
enableExpiring: false,
|
||||
expiring_at: new Date(),
|
||||
id_prev: "2",
|
||||
// id_prev: "2",
|
||||
modified: false,
|
||||
modify_at: new Date(),
|
||||
pos: 4,
|
||||
|
||||
@@ -215,19 +215,25 @@ module.exports = {
|
||||
// console.log('currentId', currentId);
|
||||
sortedList.push(item);
|
||||
} else {
|
||||
map.set(item.id_prev, i);
|
||||
map.set(String(item.id_prev), i);
|
||||
}
|
||||
}
|
||||
|
||||
while (sortedList.length < linkedList.length) {
|
||||
// get the item with a previous item ID referencing the current item
|
||||
var nextItem = linkedList[map.get(currentId)];
|
||||
if (nextItem === undefined)
|
||||
if (nextItem === undefined) {
|
||||
break;
|
||||
}
|
||||
sortedList.push(nextItem);
|
||||
currentId = String(nextItem._id);
|
||||
}
|
||||
|
||||
if (sortedList.length < linkedList.length) {
|
||||
console.log('ATTENZIONE !!! ', sortedList.length, linkedList.length);
|
||||
}
|
||||
|
||||
|
||||
// console.log('DOPO sortedList', sortedList);
|
||||
|
||||
return sortedList;
|
||||
|
||||
@@ -15,7 +15,7 @@ module.exports = Object.freeze({
|
||||
|
||||
|
||||
LIST_END: '10000000',
|
||||
LIST_START: '0',
|
||||
LIST_START: null,
|
||||
|
||||
Privacy: {
|
||||
all: 'all',
|
||||
|
||||
Reference in New Issue
Block a user