Project e Todos sistemati...
aggiunti Gruppi
This commit is contained in:
@@ -13,6 +13,9 @@ const CartSchema = new Schema({
|
||||
userId: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||
totalQty: { type: Number, default: 0 },
|
||||
totalPrice: { type: Number, default: 0 },
|
||||
department: {
|
||||
type: String, ref: 'Department'
|
||||
},
|
||||
items: [
|
||||
{
|
||||
order:
|
||||
|
||||
45
src/server/models/department.js
Executable file
45
src/server/models/department.js
Executable file
@@ -0,0 +1,45 @@
|
||||
mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
});
|
||||
|
||||
const departmentSchema = new Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
},
|
||||
username: {
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
|
||||
var Department = module.exports = mongoose.model('Department', departmentSchema);
|
||||
|
||||
module.exports.getFieldsForSearch = function () {
|
||||
return [{ field: 'name', type: tools.FieldType.string },
|
||||
{ field: 'username', type: tools.FieldType.string }
|
||||
]
|
||||
};
|
||||
|
||||
module.exports.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
module.exports.findAllIdApp = async function (idapp) {
|
||||
const myfind = { idapp };
|
||||
|
||||
return await Department.find(myfind);
|
||||
};
|
||||
|
||||
49
src/server/models/group.js
Executable file
49
src/server/models/group.js
Executable file
@@ -0,0 +1,49 @@
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
});
|
||||
|
||||
const GroupSchema = new Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
},
|
||||
descr: {
|
||||
type: String,
|
||||
},
|
||||
resp: {
|
||||
type: String,
|
||||
},
|
||||
viceResp: {
|
||||
type: String,
|
||||
},
|
||||
assignedToUsers: [
|
||||
{ type: String }
|
||||
],
|
||||
});
|
||||
|
||||
var Group = module.exports = mongoose.model('Group', GroupSchema);
|
||||
|
||||
module.exports.getFieldsForSearch = function () {
|
||||
return [{field: 'descr', type: tools.FieldType.string}]
|
||||
};
|
||||
|
||||
module.exports.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
module.exports.findAllIdApp = async function (idapp) {
|
||||
const myfind = { idapp };
|
||||
|
||||
return await Group.find(myfind);
|
||||
};
|
||||
|
||||
@@ -5,6 +5,8 @@ const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const Order = require('../models/order');
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
const OrdersCartSchema = new Schema({
|
||||
@@ -15,6 +17,9 @@ const OrdersCartSchema = new Schema({
|
||||
userId: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||
totalQty: { type: Number, default: 0 },
|
||||
totalPrice: { type: Number, default: 0 },
|
||||
department: {
|
||||
type: String, ref: 'Department'
|
||||
},
|
||||
items: [
|
||||
{
|
||||
order:
|
||||
@@ -22,7 +27,8 @@ const OrdersCartSchema = new Schema({
|
||||
}
|
||||
],
|
||||
status: {
|
||||
type: Number
|
||||
type: Number,
|
||||
Default: 0,
|
||||
},
|
||||
note: {
|
||||
type: String
|
||||
@@ -40,7 +46,16 @@ var OrdersCart = module.exports = mongoose.model('OrdersCart', OrdersCartSchema)
|
||||
module.exports.findAllIdApp = async function (idapp, userId) {
|
||||
const myfind = { idapp, userId };
|
||||
|
||||
return await OrdersCart.findOne(myfind);
|
||||
return await OrdersCart.find(myfind);
|
||||
};
|
||||
|
||||
module.exports.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
module.exports.getFieldsForSearch = function () {
|
||||
return [{field: 'note', type: tools.FieldType.string}]
|
||||
};
|
||||
|
||||
|
||||
@@ -64,7 +79,7 @@ module.exports.getNewNumOrder = async function (uid, idapp) {
|
||||
};
|
||||
|
||||
module.exports.getOrdersCartByUserId = async function (uid, idapp) {
|
||||
let query = { userId: uid, idapp, status: { $gte: shared_consts.OrderStatus.CHECKOUT_CONFIRMED } }
|
||||
let query = { userId: uid, idapp, status: { $gte: shared_consts.OrderStatus.CHECKOUT_SENT } }
|
||||
const myorderscart = await OrdersCart.find(query);
|
||||
|
||||
for (let ind = 0; ind < myorderscart.length; ind++) {
|
||||
@@ -107,6 +122,32 @@ module.exports.getOrdersCartByUserId = async function (uid, idapp) {
|
||||
// return null;
|
||||
}
|
||||
|
||||
module.exports.getOrdersCartByDepartmentId = async function (depId, idapp) {
|
||||
let query = { idapp, status: { $gte: shared_consts.OrderStatus.CHECKOUT_SENT } }
|
||||
const myorderscart = await OrdersCart.find(query);
|
||||
|
||||
for (let ind = 0; ind < myorderscart.length; ind++) {
|
||||
for (const idkey in myorderscart[ind].items) {
|
||||
try {
|
||||
idorder = myorderscart[ind].items[idkey]._id.toString();
|
||||
const myorder = myorderscart[ind].items[idkey].order;
|
||||
if (!!myorder) {
|
||||
idorder = myorderscart[ind].items[idkey].order._id.toString();
|
||||
}
|
||||
const myord = await Order.getTotalOrderById(idorder);
|
||||
if (myord.length > 0) {
|
||||
myorderscart[ind].items[idkey]._doc.order = myord[0];
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('err', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return myorderscart
|
||||
// return null;
|
||||
}
|
||||
|
||||
module.exports.updateOrdersCartById = function (id, newOrdersCart, callback) {
|
||||
let query = { id: id }
|
||||
OrdersCart.find(query, function (err, c) {
|
||||
|
||||
@@ -54,6 +54,12 @@ const productSchema = new Schema({
|
||||
quantityAvailable: {
|
||||
type: Number
|
||||
},
|
||||
quantityLow: { //Soglia disponibilità bassa
|
||||
type: Number
|
||||
},
|
||||
visibilityProductOutOfStock: { // Visibilità prodotto "esaurito"
|
||||
type: Boolean
|
||||
},
|
||||
canBeShipped: { // è spedibile
|
||||
type: Boolean
|
||||
},
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -55,13 +55,15 @@ var TodoSchema = new mongoose.Schema({
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
id_prev: mongoose.Schema.Types.ObjectId,
|
||||
progress: {
|
||||
type: Number,
|
||||
},
|
||||
phase: {
|
||||
type: Number,
|
||||
},
|
||||
assignedToUsers: [
|
||||
{ type: String }
|
||||
],
|
||||
assigned_to_userId: {
|
||||
type: String,
|
||||
},
|
||||
@@ -81,6 +83,10 @@ var TodoSchema = new mongoose.Schema({
|
||||
modified: {
|
||||
type: Boolean,
|
||||
},
|
||||
deleted: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
});
|
||||
|
||||
TodoSchema.methods.toJSON = function () {
|
||||
@@ -115,10 +121,24 @@ TodoSchema.statics.findByUserIdAndIdParent = function (userId, category, phase =
|
||||
// User.find({ admin: true }).where('created_at').gt(monthAgo).exec(function(err, users) {
|
||||
// if (err) throw err;
|
||||
|
||||
function getQueryFilterTodo(userId) {
|
||||
let myobj = [
|
||||
{ userId: userId },
|
||||
{
|
||||
$or:
|
||||
[{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }]
|
||||
}
|
||||
]
|
||||
;
|
||||
return myobj;
|
||||
}
|
||||
|
||||
/*
|
||||
function getQueryFilterTodo(userId) {
|
||||
myobj = [{ privacyread: server_constants.Privacy.all }, { userId: userId }];
|
||||
return myobj;
|
||||
}
|
||||
*/
|
||||
|
||||
function getQueryTodo(filterMatchBefore = {}, userId) {
|
||||
|
||||
@@ -150,7 +170,14 @@ function getQueryTodo(filterMatchBefore = {}, userId) {
|
||||
TodoSchema.statics.findAllByUserIdAndCat = function (userId) {
|
||||
var Todo = this;
|
||||
|
||||
const query = getQueryTodo({}, userId);
|
||||
const query = getQueryTodo({
|
||||
$or: [{ deleted: { $exists: false } }, {
|
||||
deleted: {
|
||||
$exists: true,
|
||||
$eq: false
|
||||
}
|
||||
}]
|
||||
}, userId);
|
||||
|
||||
return Todo.aggregate(query)
|
||||
.then(ris => {
|
||||
@@ -222,8 +249,8 @@ TodoSchema.statics.getAllTodo = async function (userId) {
|
||||
if (!!arralltodo) {
|
||||
const arrfiltrato = arralltodo.filter(item => item.category.toString() === mycat.toString());
|
||||
if (arrfiltrato.length > 0) {
|
||||
const arrmap = tools.mapSort(arrfiltrato);
|
||||
arrtodos.push(arrmap);
|
||||
// const arrmap = tools.mapSort(arrfiltrato);
|
||||
arrtodos.push(arrfiltrato);
|
||||
// console.log('AGGIUNGI RECORDS TODO! cat: ', mycat, 'da aggiungere:', arrfiltrato.length, 'attuali', arrtodos.length);
|
||||
// console.log(arrtodos)
|
||||
} else {
|
||||
@@ -335,7 +362,7 @@ class CalcTodo {
|
||||
if (this.mydata.numitem > 0) {
|
||||
this.mydata.progressCalc = Math.round(this.mydata.progressCalc / this.mydata.numitem);
|
||||
}
|
||||
console.log('this.mydata.progressCalc', this.mydata.progressCalc)
|
||||
// console.log('this.mydata.progressCalc', this.mydata.progressCalc)
|
||||
}
|
||||
|
||||
getData() {
|
||||
|
||||
@@ -383,6 +383,14 @@ UserSchema.statics.isZoomeri = function (perm) {
|
||||
}
|
||||
};
|
||||
|
||||
UserSchema.statics.isDepartment = function (perm) {
|
||||
try {
|
||||
return ((perm & shared_consts.Permissions.Zoomeri) === shared_consts.Permissions.Department);
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
};
|
||||
|
||||
UserSchema.statics.isTutor = function (perm) {
|
||||
try {
|
||||
return ((perm & shared_consts.Permissions.Tutor) === shared_consts.Permissions.Tutor);
|
||||
|
||||
Reference in New Issue
Block a user