Project e Todos sistemati...

aggiunti Gruppi
This commit is contained in:
Paolo Arena
2021-02-03 01:33:30 +01:00
parent 5493953b58
commit 25096e862f
28 changed files with 2962 additions and 65 deletions

View File

@@ -19,6 +19,9 @@ mongoose.plugin(schema => {
mongoose.set('debug', process.env.DEBUG);
var ProjectSchema = new mongoose.Schema({
idapp: {
type: String,
},
userId: {
type: String,
},
@@ -39,6 +42,15 @@ var ProjectSchema = new mongoose.Schema({
priority: {
type: Number,
},
groupId: {
type: String,
},
respUsername: {
type: String,
},
viceRespUsername: {
type: String,
},
statusproj: {
type: Number,
default: 0
@@ -59,7 +71,6 @@ var ProjectSchema = new mongoose.Schema({
type: Boolean,
default: false
},
id_prev: mongoose.Schema.Types.ObjectId,
modified: {
type: Boolean,
},
@@ -119,7 +130,11 @@ var ProjectSchema = new mongoose.Schema({
},
privacywrite: {
type: String
}
},
deleted: {
type: Boolean,
default: false,
},
});
@@ -164,11 +179,20 @@ ProjectSchema.statics.findProjectByUserId = function (userId, idproj) {
};
ProjectSchema.statics.findAllProjByUserId = async function (userId) {
ProjectSchema.statics.findAllProjByUserId = async function (userId, idapp) {
var Project = this;
return Project.aggregate([
{ $match: { $or: [{ privacyread: server_constants.Privacy.all }, { userId: userId }] } },
const query = [
{
$match:
{
$and: [
{ idapp }, {
$or: [{ privacyread: server_constants.Privacy.all }, { userId: userId }],
}],
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
}
},
{
$graphLookup: {
from: "projects",
@@ -176,7 +200,13 @@ ProjectSchema.statics.findAllProjByUserId = async function (userId) {
connectFromField: "id_main_project",
connectToField: "_id",
as: "ris",
restrictSearchWithMatch: { $or: [{ privacyread: server_constants.Privacy.all }, { userId: userId }] }
/* restrictSearchWithMatch: {
$or: [
{ privacyread: server_constants.Privacy.all }, { userId: userId }
]
}
*/
}
},
{ $match: { "ris.privacyread": { $exists: true } } },
@@ -188,7 +218,9 @@ ProjectSchema.statics.findAllProjByUserId = async function (userId) {
// "id_main_project": 1,
// }
// }
]).then(ris1 => {
]
return Project.aggregate(query).then(ris1 => {
// console.log('findAllProjByUserId', ris1);
@@ -211,7 +243,13 @@ ProjectSchema.statics.findAllProjByUserId = async function (userId) {
ProjectSchema.statics.getArrIdParentInTable = function (userId) {
var Project = this;
return Project.find({ 'userId': userId }).distinct("id_parent")
return Project.find(
{
'userId': userId,
$or:
[{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
}
).distinct("id_parent")
};
@@ -233,9 +271,10 @@ ProjectSchema.statics.getIdParentByIdProj = function (idProj) {
};
ProjectSchema.statics.creaProjMain = async function () {
ProjectSchema.statics.creaProjMain = async function (idapp) {
const projmain = {
idapp,
descr: process.env.PROJECT_DESCR_MAIN,
longdescr: process.env.PROJECT_DESCR_MAIN,
typeproj: 1,
@@ -255,13 +294,19 @@ ProjectSchema.statics.creaProjMain = async function () {
};
ProjectSchema.statics.getAllProjects = async function (userId) {
ProjectSchema.statics.getAllProjects = async function (userId, idapp) {
var Project = this;
// console.log('getAllProjects');
let obj = [];
const projbase = await Project.findOne( { descr: process.env.PROJECT_DESCR_MAIN })
const projbase = await Project.findOne(
{
idapp,
descr: process.env.PROJECT_DESCR_MAIN,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
})
.then(ris => {
if (!!ris) {
// console.log('ris', ris);
@@ -269,14 +314,16 @@ ProjectSchema.statics.getAllProjects = async function (userId) {
return ris._doc;
else
return null;
}else {
return Project.creaProjMain();
} else {
return Project.creaProjMain(idapp);
}
});
obj.arrproj = await Project.findAllProjByUserId(userId);
obj.arrproj = await Project.findAllProjByUserId(userId, idapp);
obj.arrproj.push(projbase);
//obj.arrproj = [...arrmap];
return obj;
};
@@ -289,8 +336,8 @@ ProjectSchema.statics.enabletoModify = async function (userId, idProj) {
return Project.findOne({
'_id': idProj,
$or: [{
'privacywrite': server_constants.Privacy.all,
'userId': userId
privacywrite: server_constants.Privacy.all,
userId: userId
}]
}).then(ris => {
return (!!ris);
@@ -308,7 +355,7 @@ ProjectSchema.statics.updateCalc = async function (userId, idproj, objdatacalc,
}
}).then((myproj) => {
if (!!myproj) {
console.log('objdatacalc progressCalc', objdatacalc.mydata.progressCalc);
// console.log('objdatacalc progressCalc', objdatacalc.mydata.progressCalc);
objdatacalc.setValuesToRecord(myproj);