Doppia modalità di Registrazione con lista extra utenti
This commit is contained in:
31
package.json
31
package.json
@@ -19,45 +19,48 @@
|
||||
"dependencies": {
|
||||
"basic-ftp": "^4.5.1",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"bluebird": "^3.7.2",
|
||||
"body-parser": "^1.19.0",
|
||||
"cors": "^2.8.4",
|
||||
"crypto-js": "^3.1.6",
|
||||
"dotenv": "^6.1.0",
|
||||
"dotenv": "^8.2.0",
|
||||
"ejs": "^2.7.1",
|
||||
"email-templates": "^5.1.0",
|
||||
"email-templates": "^6.1.1",
|
||||
"express": "^4.17.1",
|
||||
"formidable": "^1.2.1",
|
||||
"i18n": "^0.8.3",
|
||||
"jade": "^1.11.0",
|
||||
"jsonwebtoken": "^7.1.9",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"lodash": "^4.17.15",
|
||||
"mongodb": "^2.2.5",
|
||||
"mongoose": "^4.13.19",
|
||||
"mongodb": "^3.4.1",
|
||||
"mongoose": "^5.8.4",
|
||||
"mysql": "^2.17.1",
|
||||
"node-cron": "^2.0.3",
|
||||
"node-emoji": "^1.10.0",
|
||||
"node-pre-gyp": "^0.11.0",
|
||||
"node-pre-gyp": "^0.14.0",
|
||||
"node-telegram-bot-api": "^0.40.0",
|
||||
"nodemailer": "^4.6.8",
|
||||
"preview-email": "0.0.8",
|
||||
"nodemailer": "^6.4.2",
|
||||
"preview-email": "^1.0.2",
|
||||
"pug": "^2.0.4",
|
||||
"save": "^2.4.0",
|
||||
"superagent": "^5.1.3",
|
||||
"url-parse": "^1.4.7",
|
||||
"validator": "^5.6.0",
|
||||
"validator": "^12.1.0",
|
||||
"web-push": "^3.4.0",
|
||||
"xoauth2": "^1.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browser-sync": "^2.26.7",
|
||||
"expect": "^1.20.2",
|
||||
"expect": "^24.9.0",
|
||||
"gulp": "^4.0.2",
|
||||
"gulp-inline-css": "^3.4.0",
|
||||
"gulp-pug": "^4.0.1",
|
||||
"gulp-rename": "^1.4.0",
|
||||
"gulp-rename": "^2.0.0",
|
||||
"gulp-replace": "^1.0.0",
|
||||
"gulp-sass": "^4.0.2",
|
||||
"mocha": "^6.2.1",
|
||||
"nodemon": "^1.19.4",
|
||||
"supertest": "^2.0.0"
|
||||
"jest": "^24.9.0",
|
||||
"mocha": "^7.0.0",
|
||||
"nodemon": "^2.0.2",
|
||||
"supertest": "^4.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,6 +103,20 @@ if (process.env.NODE_ENV === 'production') {
|
||||
telegram_key:'1037577457:AAGQbdIuYoB838v61ewJ0Hearx9UPpTBhMI',
|
||||
telegram_bot_name: 'notevoleaynibot',
|
||||
},
|
||||
{
|
||||
idapp: '8',
|
||||
name: 'CentrOlistico Rimini',
|
||||
adminemail: 'pao.loarena77@gmail.com',
|
||||
manageremail: '',
|
||||
replyTo: 'info@arcodiluce.it',
|
||||
host: 'https://www.centrolisticorimini.it',
|
||||
portapp: '0',
|
||||
dir: '/var/www/centrolisticorimini.it',
|
||||
email_from: 'info.pianetalibero@gmail.com', // ++TODO: Sarà da cambiare email d'invio !?!?!?
|
||||
email_pwd: '2df135e2b6c02b2c68ec6bf6b103751fcb4dfc48c57d0acb302482358ee8141fmaDuooPabDvlThiBI2XMyA==',
|
||||
telegram_key:'',
|
||||
telegram_bot_name: '',
|
||||
},
|
||||
];
|
||||
} else if (process.env.NODE_ENV === 'test') {
|
||||
// ---------------- AMBIENTE DI TEST --------------------
|
||||
@@ -187,6 +201,20 @@ if (process.env.NODE_ENV === 'production') {
|
||||
telegram_key:'1011893908:AAEThZB3fVPw8P5gTCFgTEsDmY21DdbV1Cw',
|
||||
telegram_bot_name: 'testnotevoleaynibot',
|
||||
},
|
||||
{
|
||||
idapp: '8',
|
||||
name: 'CentrOlistico Rimini',
|
||||
adminemail: 'pao.loarena77@gmail.com',
|
||||
manageremail: '',
|
||||
replyTo: 'info@arcodiluce.it',
|
||||
host: 'https://www.centrolisticorimini.it',
|
||||
portapp: '0',
|
||||
dir: '/var/www/centrolisticorimini.it',
|
||||
email_from: 'info.pianetalibero@gmail.com', // ++TODO: Sarà da cambiare email d'invio !?!?!?
|
||||
email_pwd: '2df135e2b6c02b2c68ec6bf6b103751fcb4dfc48c57d0acb302482358ee8141fmaDuooPabDvlThiBI2XMyA==',
|
||||
telegram_key:'',
|
||||
telegram_bot_name: '',
|
||||
},
|
||||
];
|
||||
} else {
|
||||
// ---------------- AMBIENTE IN L O C A L E --------------------
|
||||
@@ -269,6 +297,20 @@ if (process.env.NODE_ENV === 'production') {
|
||||
telegram_bot_name: 'paotestlocalebot',
|
||||
telegram_key:'353996190:AAEcEbfrm_zTK6mBKf8ye9j-PXt958SDxew',
|
||||
},
|
||||
{
|
||||
idapp: '8',
|
||||
name: 'CentrOlistico Rimini',
|
||||
adminemail: 'pao.loarena77@gmail.com',
|
||||
manageremail: '',
|
||||
replyTo: 'info@arcodiluce.it',
|
||||
host: 'http://localhost',
|
||||
portapp: '8086',
|
||||
dir: '/home/paolo/myproject/centrolisticorimini.it/dist/spa',
|
||||
email_from: 'info.pianetalibero@gmail.com',
|
||||
email_pwd: '66ffeb915e71fada64ad5c26947dd087c262be3b343734a0447c6dee534b888aZcfbjXEuMBWKxvbh60cniw==',
|
||||
telegram_key:'',
|
||||
telegram_bot_name: '',
|
||||
},
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
@@ -11,15 +11,18 @@ mongoose.plugin(schema => {
|
||||
|
||||
mongoose.set('debug', false);
|
||||
|
||||
var options = {
|
||||
const options = {
|
||||
// user: process.env.UDB,
|
||||
// pass: process.env.PDB,
|
||||
useMongoClient: true,
|
||||
// useMongoClient: true,
|
||||
// useNewUrlParser: true, // non supportato
|
||||
promiseLibrary: require('bluebird')
|
||||
useNewUrlParser: true,
|
||||
useFindAndModify: false,
|
||||
useCreateIndex: true,
|
||||
useUnifiedTopology: true,
|
||||
|
||||
promiseLibrary: require('bluebird'),
|
||||
|
||||
// useCreateIndex: true,
|
||||
// useFindAndModify: false,
|
||||
// autoIndex: false, // Don't build indexes
|
||||
// reconnectTries: Number.MAX_VALUE, // Never stop trying to reconnect
|
||||
// reconnectInterval: 500, // Reconnect every 500ms
|
||||
@@ -35,13 +38,17 @@ var options = {
|
||||
};
|
||||
|
||||
|
||||
const db = mongoose.connection;
|
||||
|
||||
|
||||
// mongoose.connect(process.env.MONGODB_URI + '?authSource=admin', { options })
|
||||
mongoose.connect(process.env.MONGODB_URI, options)
|
||||
.then(() =>
|
||||
mongoose.connect(process.env.MONGODB_URI, options);
|
||||
|
||||
db.on('error', console.error.bind(console, 'connection error:'));
|
||||
db.once('open', function() {
|
||||
// we're connected!
|
||||
console.log('connection succesful ' + process.env.MONGODB_URI + ' db: ' + process.env.DATABASE)
|
||||
|
||||
)
|
||||
.catch((err) => console.error(err));
|
||||
});
|
||||
|
||||
module.exports = {mongoose};
|
||||
|
||||
@@ -13,8 +13,8 @@ const authenticate = (req, res, next) => {
|
||||
|
||||
User.findByToken(token, access).then((user) => {
|
||||
if (!user) {
|
||||
tools.mylog("TOKEN " + token);
|
||||
tools.mylog(" NOT FOUND! (Maybe Connected to other Page) ACCESS: '" + access + "'");
|
||||
// tools.mylog("TOKEN " + token);
|
||||
// tools.mylog(" NOT FOUND! (Maybe Connected to other Page) ACCESS: '" + access + "'");
|
||||
return Promise.reject(server_constants.RIS_CODE_HTTP_INVALID_TOKEN);
|
||||
// res.status().send();
|
||||
}
|
||||
|
||||
@@ -33,6 +33,13 @@ ContribtypeSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
ContribtypeSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
|
||||
|
||||
return tools.DuplicateAllRecords(this, idapporig, idappdest);
|
||||
|
||||
};
|
||||
|
||||
|
||||
ContribtypeSchema.statics.findAllIdApp = function (idapp) {
|
||||
const Contribtype = this;
|
||||
|
||||
|
||||
@@ -97,6 +97,12 @@ DisciplineSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
DisciplineSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
|
||||
|
||||
return tools.DuplicateAllRecords(this, idapporig, idappdest);
|
||||
|
||||
};
|
||||
|
||||
const Discipline = mongoose.model('Discipline', DisciplineSchema);
|
||||
|
||||
module.exports = { Discipline };
|
||||
|
||||
265
src/server/models/extralist.js
Normal file
265
src/server/models/extralist.js
Normal file
@@ -0,0 +1,265 @@
|
||||
var bcrypt = require('bcryptjs');
|
||||
const mongoose = require('mongoose');
|
||||
const validator = require('validator');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const _ = require('lodash');
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
const queryclass = require('../classes/queryclass');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
|
||||
mongoose.level = "F";
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
});
|
||||
|
||||
mongoose.set('debug', process.env.DEBUG);
|
||||
|
||||
var ExtraListSchema = new mongoose.Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
ind_order: {
|
||||
type: Number,
|
||||
},
|
||||
date_reg: {
|
||||
type: Date,
|
||||
},
|
||||
name_complete: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
username: {
|
||||
type: String,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
surname: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
num_invitati: {
|
||||
type: Number,
|
||||
},
|
||||
is_in_whatsapp: {
|
||||
type: Boolean,
|
||||
},
|
||||
is_in_telegram: {
|
||||
type: Boolean,
|
||||
},
|
||||
cell_complete: {
|
||||
type: String
|
||||
},
|
||||
nationality: {
|
||||
type: String
|
||||
},
|
||||
aportador_solidario_name_surname: {
|
||||
type: String,
|
||||
},
|
||||
aportador_solidario_ind_order: {
|
||||
type: Number,
|
||||
},
|
||||
aportador_solidario_originale_name_surname: {
|
||||
type: String,
|
||||
},
|
||||
note: {
|
||||
type: String,
|
||||
},
|
||||
col_b: {
|
||||
type: Number,
|
||||
},
|
||||
col_h: {
|
||||
type: Number,
|
||||
},
|
||||
registered: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
ExtraListSchema.methods.toJSON = function () {
|
||||
var user = this;
|
||||
var userObject = user.toObject();
|
||||
|
||||
return _.pick(userObject, ['_id', ...shared_consts.fieldsUserToChange()]);
|
||||
};
|
||||
|
||||
ExtraListSchema.statics.findByUsername = function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
return User.findOne({
|
||||
'idapp': idapp,
|
||||
'username': username,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
ExtraListSchema.statics.findByCellAndNameSurname = function (idapp, cell_complete, name, surname) {
|
||||
var User = this;
|
||||
|
||||
return User.findOne({
|
||||
'idapp': idapp,
|
||||
'cell_complete': cell_complete,
|
||||
'name': name,
|
||||
'surname': surname,
|
||||
});
|
||||
};
|
||||
|
||||
ExtraListSchema.statics.findByIndOrder = function (idapp, ind_order) {
|
||||
const User = this;
|
||||
|
||||
try {
|
||||
return User.findOne({
|
||||
'idapp': idapp,
|
||||
'ind_order': ind_order,
|
||||
});
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ExtraListSchema.statics.getUsersList = function (idapp) {
|
||||
const User = this;
|
||||
|
||||
return User.find({ 'idapp': idapp }, {
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
date_reg: 1,
|
||||
})
|
||||
|
||||
};
|
||||
|
||||
|
||||
ExtraListSchema.statics.getFieldsForSearch = function () {
|
||||
return ['name', 'surname', 'cell_complete', 'aportador_solidario_name_surname', 'aportador_solidario_originale_name_surname']
|
||||
};
|
||||
|
||||
ExtraListSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
ExtraListSchema.statics.findAllIdApp = function (idapp) {
|
||||
const ExtraList = this;
|
||||
|
||||
const myfind = { idapp };
|
||||
|
||||
return ExtraList.find(myfind, (err, arrrec) => {
|
||||
return arrrec
|
||||
});
|
||||
};
|
||||
|
||||
ExtraListSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
|
||||
|
||||
return tools.DuplicateAllRecords(this, idapporig, idappdest);
|
||||
|
||||
};
|
||||
|
||||
|
||||
ExtraListSchema.statics.ImportData = async function (locale, idapp, strdata) {
|
||||
|
||||
const ExtraList = this;
|
||||
|
||||
try {
|
||||
let numadded = 0;
|
||||
let numtot = 0;
|
||||
let numalreadyexisted = 0;
|
||||
|
||||
// Convert to array
|
||||
let arrusers = strdata.split('\n');
|
||||
let sep = ',';
|
||||
|
||||
// console.log('arrusers', arrusers);
|
||||
|
||||
try {
|
||||
for (const row of arrusers) {
|
||||
console.log('row', row);
|
||||
if (sep !== '' && row !== '') {
|
||||
let col = row.split(sep);
|
||||
if (col) {
|
||||
if (col.length > 0) {
|
||||
let user = null;
|
||||
try {
|
||||
user = new ExtraList({
|
||||
idapp: idapp,
|
||||
ind_order: col[0],
|
||||
name_complete: col[2],
|
||||
num_invitati: col[3],
|
||||
is_in_whatsapp: col[4] !== '',
|
||||
is_in_telegram: col[5] !== '',
|
||||
cell_complete: col[6],
|
||||
nationality: col[7],
|
||||
aportador_solidario_name_surname: col[8],
|
||||
aportador_solidario_ind_order: col[9],
|
||||
aportador_solidario_originale_name_surname: col[10],
|
||||
note: col[11],
|
||||
col_b: col[12],
|
||||
col_h: col[13]
|
||||
});
|
||||
|
||||
try {
|
||||
user.date_reg = col[1];
|
||||
} catch (e) {
|
||||
console.log('error ', e);
|
||||
}
|
||||
|
||||
namesurname = tools.extractNameAndSurnameByComplete(user.name_complete);
|
||||
user.name = namesurname.name;
|
||||
user.surname = namesurname.surname;
|
||||
|
||||
if (user.name && user.surname && user.cell_complete) {
|
||||
// Save into db
|
||||
await user.save();
|
||||
numadded++;
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.log('error ', e, col);
|
||||
}
|
||||
|
||||
numtot++;
|
||||
}
|
||||
// numalreadyexisted++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
ris = { numadded, numtot, numalreadyexisted };
|
||||
|
||||
console.log(ris);
|
||||
return ris
|
||||
|
||||
} catch (e) {
|
||||
console.err(e);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
if (tools.INITDB_FIRSTIME) {
|
||||
console.log(' createIndex User Index...');
|
||||
// ExtraListSchema.index({ username: 'text', name: 'text', surname: 'text', email: 'text' });
|
||||
// ExtraListSchema.index({ name: 'name' });
|
||||
// ExtraListSchema.index({ name: 1 });
|
||||
// ExtraListSchema.index({ surname: 1 });
|
||||
}
|
||||
|
||||
const ExtraList = mongoose.model('ExtraList', ExtraListSchema);
|
||||
|
||||
|
||||
module.exports = { ExtraList };
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ MailingListSchema.statics.getnumSent = async function (idapp, idmailinglist) {
|
||||
|
||||
// Extract only the Teacher where in the users table the field permissions is set 'Teacher' bit.
|
||||
|
||||
return await MailingList.find(myfind).count();
|
||||
return await MailingList.countDocuments(myfind);
|
||||
};
|
||||
|
||||
MailingListSchema.statics.isOk = async function (idapp, iduser, idmailinglist) {
|
||||
@@ -82,7 +82,7 @@ MailingListSchema.statics.isOk = async function (idapp, iduser, idmailinglist) {
|
||||
|
||||
// Extract only the Teacher where in the users table the field permissions is set 'Teacher' bit.
|
||||
|
||||
return await MailingList.find(myfind).count() > 0;
|
||||
return await MailingList.countDocuments(myfind) > 0;
|
||||
};
|
||||
|
||||
MailingListSchema.statics.findAllIdApp = async function (idapp) {
|
||||
|
||||
@@ -32,7 +32,6 @@ OpzEmailSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
return tools.executeQueryTable(this, 0, params);
|
||||
};
|
||||
|
||||
|
||||
OpzEmailSchema.statics.findAllIdApp = async function (idapp) {
|
||||
const OpzEmail = this;
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ const Schema = mongoose.Schema;
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
|
||||
@@ -73,16 +75,27 @@ SettingsSchema.statics.getValDbSettings = function (idapp, key, def) {
|
||||
|
||||
};
|
||||
|
||||
SettingsSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
|
||||
|
||||
return tools.DuplicateAllRecords(this, idapporig, idappdest);
|
||||
|
||||
};
|
||||
|
||||
SettingsSchema.statics.findAllIdApp = function (idapp, serv) {
|
||||
const Settings = this;
|
||||
|
||||
const myfind = { idapp, serv };
|
||||
let myfind = '';
|
||||
if (serv)
|
||||
myfind = { idapp, serv };
|
||||
else
|
||||
myfind = { idapp };
|
||||
|
||||
return Settings.find(myfind, (err, arrrec) => {
|
||||
return arrrec
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
const Settings = mongoose.model('Settings', SettingsSchema);
|
||||
|
||||
module.exports = { Settings };
|
||||
|
||||
@@ -49,6 +49,12 @@ TemplEmailSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
TemplEmailSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
|
||||
|
||||
return tools.DuplicateAllRecords(this, idapporig, idappdest);
|
||||
|
||||
};
|
||||
|
||||
|
||||
TemplEmailSchema.statics.findAllIdApp = async function (idapp) {
|
||||
const TemplEmail = this;
|
||||
|
||||
@@ -163,7 +163,7 @@ TodoSchema.statics.findAllByUserIdAndCat = function (userId) {
|
||||
TodoSchema.statics.getArrIdParentInTable = function (userId) {
|
||||
var Todo = this;
|
||||
|
||||
return Todo.find(getQueryFilterTodo(userId)).distinct("category")
|
||||
return Todo.find(getQueryFilterTodo(userId)[0]).distinct("category")
|
||||
.then(arrcategory => {
|
||||
return arrcategory
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var bcrypt = require('bcryptjs');
|
||||
const bcrypt = require('bcryptjs');
|
||||
const mongoose = require('mongoose');
|
||||
const validator = require('validator');
|
||||
const jwt = require('jsonwebtoken');
|
||||
@@ -19,10 +19,13 @@ mongoose.plugin(schema => {
|
||||
|
||||
mongoose.set('debug', process.env.DEBUG);
|
||||
|
||||
var UserSchema = new mongoose.Schema({
|
||||
const UserSchema = new mongoose.Schema({
|
||||
userId: {
|
||||
type: String,
|
||||
},
|
||||
already_registered: {
|
||||
type: Boolean,
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
required: true,
|
||||
@@ -38,6 +41,9 @@ var UserSchema = new mongoose.Schema({
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
ind_order: {
|
||||
type: Number
|
||||
},
|
||||
username: {
|
||||
type: String,
|
||||
required: true,
|
||||
@@ -114,6 +120,12 @@ var UserSchema = new mongoose.Schema({
|
||||
aportador_solidario: {
|
||||
type: String,
|
||||
},
|
||||
aportador_solidario_nome_completo: {
|
||||
type: String,
|
||||
},
|
||||
aportador_solidario_ind_order: {
|
||||
type: Number,
|
||||
},
|
||||
profile: {
|
||||
img: {
|
||||
type: String
|
||||
@@ -160,15 +172,15 @@ var UserSchema = new mongoose.Schema({
|
||||
});
|
||||
|
||||
UserSchema.methods.toJSON = function () {
|
||||
var user = this;
|
||||
var userObject = user.toObject();
|
||||
const user = this;
|
||||
const userObject = user.toObject();
|
||||
|
||||
return _.pick(userObject, ['_id', ...shared_consts.fieldsUserToChange()]);
|
||||
};
|
||||
|
||||
UserSchema.methods.generateAuthToken = function (req) {
|
||||
// console.log("GENERA TOKEN : ");
|
||||
var user = this;
|
||||
const user = this;
|
||||
|
||||
const useragent = req.get('User-Agent');
|
||||
// tools.mylog("GENERATE USER-AGENT = ", useragent);
|
||||
@@ -208,7 +220,7 @@ UserSchema.statics.setPermissionsById = function (id, perm) {
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.isAdmin = function (user) {
|
||||
UserSchema.statics.isAdmin = function (perm) {
|
||||
try {
|
||||
return ((perm & shared_consts.Permissions.Admin) === shared_consts.Permissions.Admin);
|
||||
} catch (e) {
|
||||
@@ -242,8 +254,8 @@ UserSchema.statics.findByToken = function (token, typeaccess) {
|
||||
};
|
||||
|
||||
UserSchema.statics.findByTokenAnyAccess = function (token) {
|
||||
var User = this;
|
||||
var decoded;
|
||||
const User = this;
|
||||
let decoded;
|
||||
|
||||
try {
|
||||
decoded = jwt.verify(token, process.env.SIGNCODE);
|
||||
@@ -258,8 +270,8 @@ UserSchema.statics.findByTokenAnyAccess = function (token) {
|
||||
};
|
||||
|
||||
UserSchema.statics.findByCredentials = function (idapp, username, password) {
|
||||
var User = this;
|
||||
var pwd = "";
|
||||
const User = this;
|
||||
let pwd = "";
|
||||
|
||||
return User.findOne({ idapp, username: username }).then((user) => {
|
||||
if (!user) {
|
||||
@@ -345,7 +357,7 @@ UserSchema.statics.getDownlineByUsername = function (idapp, username) {
|
||||
};
|
||||
|
||||
UserSchema.statics.findByLinkreg = function (idapp, linkreg) {
|
||||
var User = this;
|
||||
const User = this;
|
||||
|
||||
return User.findOne({
|
||||
'linkreg': linkreg,
|
||||
@@ -354,7 +366,7 @@ UserSchema.statics.findByLinkreg = function (idapp, linkreg) {
|
||||
};
|
||||
|
||||
UserSchema.statics.findByLinkTokenforgot = function (idapp, email, tokenforgot) {
|
||||
var User = this;
|
||||
const User = this;
|
||||
|
||||
return User.findOne({
|
||||
'email': email,
|
||||
@@ -366,7 +378,7 @@ UserSchema.statics.findByLinkTokenforgot = function (idapp, email, tokenforgot)
|
||||
|
||||
|
||||
UserSchema.statics.findByEmail = function (idapp, email) {
|
||||
var User = this;
|
||||
const User = this;
|
||||
|
||||
return User.findOne({
|
||||
'idapp': idapp,
|
||||
@@ -375,7 +387,7 @@ UserSchema.statics.findByEmail = function (idapp, email) {
|
||||
};
|
||||
|
||||
UserSchema.pre('save', function (next) {
|
||||
var user = this;
|
||||
const user = this;
|
||||
|
||||
|
||||
/*
|
||||
@@ -396,7 +408,7 @@ UserSchema.pre('save', function (next) {
|
||||
UserSchema.methods.removeToken = function (token) {
|
||||
const user = this;
|
||||
|
||||
return user.update({
|
||||
return user.updateOne({
|
||||
$pull: {
|
||||
tokens: { token }
|
||||
}
|
||||
@@ -552,6 +564,22 @@ UserSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
UserSchema.statics.findAllIdApp = function (idapp) {
|
||||
const User = this;
|
||||
|
||||
const myfind = { idapp };
|
||||
|
||||
return User.find(myfind, (err, arrrec) => {
|
||||
return arrrec
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) {
|
||||
|
||||
return tools.DuplicateAllRecords(this, idapporig, idappdest);
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, username) {
|
||||
try {
|
||||
|
||||
@@ -577,6 +605,24 @@ UserSchema.statics.getDashboard = async function (idapp, aportador_solidario, us
|
||||
}
|
||||
};
|
||||
|
||||
UserSchema.statics.fixUsername = async function (idapp, aportador_solidario_ind_order, username) {
|
||||
const User = this;
|
||||
|
||||
// Check if somewhere there is my username
|
||||
return User.find({ idapp, aportador_solidario_ind_order }, async (err, arrrec) => {
|
||||
if (arrrec) {
|
||||
for (const myuser of arrrec) {
|
||||
if (!myuser.aportador_solidario || myuser.aportador_solidario === tools.APORTADOR_NONE) {
|
||||
myuser.aportador_solidario = username;
|
||||
await myuser.save()
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
if (tools.INITDB_FIRSTIME) {
|
||||
console.log(' createIndex User Index...');
|
||||
|
||||
@@ -6,7 +6,7 @@ module.exports = {
|
||||
try {
|
||||
if (tablename === 'users') {
|
||||
// Delete also all the subscribers record of this User
|
||||
return Subscription.remove({ userId: rec._id })
|
||||
return Subscription.deleteOne({ userId: rec._id })
|
||||
}
|
||||
} catch (e) {
|
||||
return false
|
||||
|
||||
@@ -22,6 +22,7 @@ if (!fs.existsSync(folder)) {
|
||||
const _ = require('lodash');
|
||||
|
||||
const { User } = require('../models/user');
|
||||
const { ExtraList } = require('../models/extralist');
|
||||
const { Booking } = require('../models/booking');
|
||||
const { Operator } = require('../models/operator');
|
||||
const { Where } = require('../models/where');
|
||||
@@ -150,6 +151,8 @@ function getTableByTableName(tablename) {
|
||||
mytable = '';
|
||||
if (tablename === 'users')
|
||||
mytable = User;
|
||||
else if (tablename === 'extralist')
|
||||
mytable = ExtraList;
|
||||
else if (tablename === 'bookings')
|
||||
mytable = Booking;
|
||||
else if (tablename === 'operators')
|
||||
@@ -269,6 +272,35 @@ router.patch('/chval', authenticate, (req, res) => {
|
||||
})
|
||||
});
|
||||
|
||||
router.get('/copyfromapptoapp/:idapporig/:idappdest', async (req, res) => {
|
||||
const idapporig = req.params.idapporig;
|
||||
const idappdest = req.params.idappdest;
|
||||
if (!idapporig || !idappdest)
|
||||
res.status(400).send();
|
||||
|
||||
const mytablesstr = ['settings', 'users', 'templemail', 'contribtype'];
|
||||
|
||||
try {
|
||||
let numrectot = 0;
|
||||
for (const table of mytablesstr) {
|
||||
const mytable = getTableByTableName(table);
|
||||
|
||||
tools.mylogshow('copyfromapptoapp: ', table, mytable);
|
||||
|
||||
await mytable.DuplicateAllRecords(idapporig, idappdest).then((numrec) => {
|
||||
// tools.mylogshow(' REC TO MODIFY: ', rec);
|
||||
numrectot += numrec
|
||||
});
|
||||
}
|
||||
|
||||
res.send({ code: server_constants.RIS_CODE_OK, msg: '', numrectot });
|
||||
|
||||
} catch (e) {
|
||||
tools.mylogserr('Error copyfromapptoapp: ', e);
|
||||
res.status(400).send();
|
||||
}
|
||||
});
|
||||
|
||||
router.delete('/delrec/:table/:id', authenticate, (req, res) => {
|
||||
const id = req.params.id;
|
||||
const tablename = req.params.table;
|
||||
|
||||
@@ -20,7 +20,7 @@ const { ObjectID } = require('mongodb');
|
||||
router.post('/', authenticate, (req, res) => {
|
||||
|
||||
var body = _.pick(req.body, tools.allfieldProjectWithId());
|
||||
tools.mylogshow('PROJ INPUT', body);
|
||||
// tools.mylogshow('PROJ INPUT', body);
|
||||
var project = new Project(body);
|
||||
|
||||
// project.expiring_at = new Date(project.expiring_at);
|
||||
@@ -45,7 +45,7 @@ router.post('/', authenticate, (req, res) => {
|
||||
let idobj = writeresult._id;
|
||||
Project.findById(idobj)
|
||||
.then(record => {
|
||||
tools.mylog('REC SAVED :', record.descr);
|
||||
// tools.mylog('REC SAVED :', record.descr);
|
||||
|
||||
tools.sendNotificationToUser(project.userId, 'Project: ' + record.descr, record.descr, '/project/' + project.category, 'project')
|
||||
.then(ris => {
|
||||
|
||||
70
src/server/router/test_router.js
Normal file
70
src/server/router/test_router.js
Normal file
@@ -0,0 +1,70 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
var server_constants = require('../tools/server_constants');
|
||||
|
||||
var { Project } = require('../models/project');
|
||||
|
||||
var { authenticate } = require('../middleware/authenticate');
|
||||
|
||||
var mongoose = require('mongoose');
|
||||
const Subscription = mongoose.model('subscribers');
|
||||
|
||||
var { Todo } = require('../models/todo');
|
||||
const { Settings } = require('../models/settings');
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
|
||||
const todo = {
|
||||
// category: "personal",
|
||||
statustodo: 0,
|
||||
completed_at: new Date(),
|
||||
created_at: new Date(),
|
||||
descr: "Primo Task Esempio",
|
||||
enableExpiring: false,
|
||||
expiring_at: new Date(),
|
||||
id_prev: null,
|
||||
modified: false,
|
||||
modify_at: new Date(),
|
||||
pos: 1,
|
||||
priority: 1,
|
||||
progress: 0,
|
||||
userId: '5e135ede41a7ee26519464f7'
|
||||
};
|
||||
|
||||
const myrec = new Todo(todo);
|
||||
myrec._id = new ObjectID();
|
||||
|
||||
const TodoOne = myrec.save().then((ris, err) => {
|
||||
console.log('Err:', err);
|
||||
console.log('Ris:', ris);
|
||||
|
||||
});
|
||||
|
||||
|
||||
const newrec = new Settings({ key: 'chiave1' });
|
||||
newrec._id = new ObjectID();
|
||||
newrec.idapp = '8';
|
||||
|
||||
newrec.save((err, rec) => {
|
||||
if (err)
|
||||
console.log('ERROR: ', err);
|
||||
if (rec) {
|
||||
console.log('SAVED? ', rec);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
res.send({});
|
||||
|
||||
});
|
||||
|
||||
|
||||
module.exports = router;
|
||||
@@ -22,12 +22,12 @@ const { ObjectID } = require('mongodb');
|
||||
router.post('/', authenticate, (req, res) => {
|
||||
|
||||
var body = _.pick(req.body, tools.allfieldTodoWithId());
|
||||
tools.mylogshow('INPUT', body);
|
||||
// tools.mylogshow('INPUT', body);
|
||||
var todo = new Todo(body);
|
||||
|
||||
// todo.expiring_at = new Date(todo.expiring_at);
|
||||
|
||||
tools.mylog('ID :', todo._id, todo.descr, todo.userId, req.user._id);
|
||||
// tools.mylog('ID :', todo._id, todo.descr, todo.userId, req.user._id);
|
||||
|
||||
if (!('descr' in req.body)) {
|
||||
return res.status(400).send({ code: server_constants.RIS_CODE_LOGIN_ERR_GENERIC });
|
||||
@@ -39,7 +39,7 @@ router.post('/', authenticate, (req, res) => {
|
||||
return res.status(404).send({ code: server_constants.RIS_CODE_TODO_CREATING_NOTMYUSER });
|
||||
}
|
||||
|
||||
tools.mylog('TODO POST :', todo.descr, todo._id);
|
||||
// tools.mylog('TODO POST :', todo.descr, todo._id);
|
||||
|
||||
todo.modified = false;
|
||||
if (!todo.descr) {
|
||||
@@ -50,7 +50,7 @@ router.post('/', authenticate, (req, res) => {
|
||||
let idobj = writeresult._id;
|
||||
Todo.findById(idobj)
|
||||
.then(record => {
|
||||
tools.mylog('REC SAVED :', record.descr);
|
||||
// tools.mylog('REC SAVED :', record.descr);
|
||||
|
||||
tools.sendNotificationToUser(todo.userId, 'Todo: ' + record.descr, record.descr, '/todo/' + todo.category, 'todo')
|
||||
.then(ris => {
|
||||
@@ -72,7 +72,7 @@ router.patch('/:id', authenticate, (req, res) => {
|
||||
var id = req.params.id;
|
||||
var body = _.pick(req.body, tools.allfieldTodo());
|
||||
|
||||
tools.mylogshow('PATCH TODO: ', id);
|
||||
// tools.mylogshow('PATCH TODO: ', id);
|
||||
|
||||
if (!ObjectID.isValid(id)) {
|
||||
tools.mylog('ERROR: id not VALID', id);
|
||||
@@ -90,7 +90,7 @@ router.patch('/:id', authenticate, (req, res) => {
|
||||
let level = 0;
|
||||
return Todo.calculateTreeTodo(todo.phase, todo.userId, todo.category, true, todo.category, false)
|
||||
.then(objdatacalc => {
|
||||
tools.mylogshow(' TODO TO MODIFY: ', todo.descr, todo.expiring_at);
|
||||
// tools.mylogshow(' TODO TO MODIFY: ', todo.descr, todo.expiring_at);
|
||||
|
||||
if (todo.userId !== String(req.user._id)) {
|
||||
// I'm trying to write something not mine!
|
||||
@@ -99,7 +99,7 @@ router.patch('/:id', authenticate, (req, res) => {
|
||||
|
||||
todo.modified = false;
|
||||
|
||||
tools.mylog('PATCH ', todo.descr, todo._id);
|
||||
// tools.mylog('PATCH ', todo.descr, todo._id);
|
||||
|
||||
res.send({ todo, objdatacalc });
|
||||
});
|
||||
@@ -115,7 +115,7 @@ router.get('/:userId', authenticate, (req, res) => {
|
||||
var userId = req.params.userId;
|
||||
// var category = req.params.category;
|
||||
|
||||
tools.mylog('GET TODOS : ', req.params);
|
||||
// tools.mylog('GET TODOS : ', req.params);
|
||||
|
||||
if (!ObjectID.isValid(userId)) {
|
||||
return res.status(404).send();
|
||||
@@ -129,8 +129,8 @@ router.get('/:userId', authenticate, (req, res) => {
|
||||
// Extract all the todos of the userId only
|
||||
Todo.getAllTodo(userId).then((objtodos) => {
|
||||
if (!!objtodos.arrtodos) {
|
||||
tools.mylog('todos', objtodos.arrtodos.length);
|
||||
tools.mylog('categories', objtodos.arrcategories.length);
|
||||
// tools.mylog('todos', objtodos.arrtodos.length);
|
||||
// tools.mylog('categories', objtodos.arrcategories.length);
|
||||
}
|
||||
|
||||
res.send({ todos: objtodos.arrtodos, categories: objtodos.arrcategories });
|
||||
@@ -141,16 +141,46 @@ router.get('/:userId', authenticate, (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.get('/test', (req, res) => {
|
||||
|
||||
const todo = {
|
||||
_id: new ObjectID(),
|
||||
// category: "personal",
|
||||
statustodo: 0,
|
||||
completed_at: new Date(),
|
||||
created_at: new Date(),
|
||||
descr: "Primo Task Esempio",
|
||||
enableExpiring: false,
|
||||
expiring_at: new Date(),
|
||||
id_prev: null,
|
||||
modified: false,
|
||||
modify_at: new Date(),
|
||||
pos: 1,
|
||||
priority: 1,
|
||||
progress: 0,
|
||||
userId: users[0]._id
|
||||
};
|
||||
|
||||
const TodoOne = new Todo(todo).save().then((err, ris) => {
|
||||
console.log('Err:', err);
|
||||
console.log('Ris:', ris);
|
||||
|
||||
});
|
||||
|
||||
res.send({ });
|
||||
|
||||
});
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
// var category = req.params.category;
|
||||
|
||||
tools.mylog('GET ALL TODOS ');
|
||||
// tools.mylog('GET ALL TODOS ');
|
||||
|
||||
// Extract all the todos of the userId only
|
||||
Todo.getAllTodo('').then((objtodos) => {
|
||||
if (!!objtodos.arrtodos) {
|
||||
tools.mylog('todos', objtodos.arrtodos.length);
|
||||
tools.mylog('categories', objtodos.arrcategories.length);
|
||||
// tools.mylog('todos', objtodos.arrtodos.length);
|
||||
// tools.mylog('categories', objtodos.arrcategories.length);
|
||||
}
|
||||
|
||||
res.send({ todos: objtodos.arrtodos, categories: objtodos.arrcategories });
|
||||
@@ -173,7 +203,7 @@ router.delete('/:id', authenticate, (req, res) => {
|
||||
return res.status(404).send();
|
||||
}
|
||||
|
||||
tools.mylog('DELETED ', todo.descr, todo._id);
|
||||
// tools.mylog('DELETED ', todo.descr, todo._id);
|
||||
|
||||
res.send({ todo });
|
||||
}).catch((e) => {
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
var { User } = require('../models/user');
|
||||
const { User } = require('../models/user');
|
||||
const { ExtraList } = require('../models/extralist');
|
||||
|
||||
var sendemail = require('../sendemail');
|
||||
const sendemail = require('../sendemail');
|
||||
|
||||
const tools = require('../tools/general');
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
var server_constants = require('../tools/server_constants');
|
||||
const server_constants = require('../tools/server_constants');
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
var reg = require('../reg/registration');
|
||||
const reg = require('../reg/registration');
|
||||
|
||||
var { authenticate } = require('../middleware/authenticate');
|
||||
const { authenticate } = require('../middleware/authenticate');
|
||||
|
||||
var mongoose = require('mongoose');
|
||||
const mongoose = require('mongoose');
|
||||
const Subscription = mongoose.model('subscribers');
|
||||
|
||||
function existSubScribe(userId, access, browser) {
|
||||
@@ -30,10 +31,20 @@ function existSubScribe(userId, access, browser) {
|
||||
|
||||
}
|
||||
|
||||
function getMobileComplete(user) {
|
||||
let str = user.profile.intcode_cell + user.profile.cell;
|
||||
str = str.replace(/\s+/g, '');
|
||||
// str = str.replace(/.+/g, '');
|
||||
// str = str.replace(/-+/g, '');
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
|
||||
// POST /users
|
||||
router.post('/', async (req, res) => {
|
||||
tools.mylog("POST /users");
|
||||
const body = _.pick(req.body, ['email', 'password', 'username', 'name', 'surname', 'idapp', 'keyappid', 'lang', 'profile', 'aportador_solidario']);
|
||||
const body = _.pick(req.body, ['email', 'password', 'username', 'name', 'surname', 'idapp', 'keyappid', 'lang', 'profile', 'aportador_solidario', 'already_registered']);
|
||||
const user = new User(body);
|
||||
|
||||
// tools.mylog("LANG PASSATO = " + user.lang, "IDAPP", user.idapp);
|
||||
@@ -73,8 +84,34 @@ router.post('/', async (req, res) => {
|
||||
if (exit === 1)
|
||||
return;
|
||||
|
||||
user.save().then(() => {
|
||||
User.findByUsername(user.idapp, user.username)
|
||||
let recextra = null;
|
||||
|
||||
if (user.already_registered) {
|
||||
// Check in the extraList if is present!
|
||||
recextra = await ExtraList.findByCellAndNameSurname(user.idapp, getMobileComplete(user), user.name, user.surname);
|
||||
if (!recextra) {
|
||||
res.status(400).send({ code: server_constants.RIS_CODE_USER_EXTRALIST_NOTFOUND, msg: '' });
|
||||
return 1;
|
||||
} else {
|
||||
user.ind_order = recextra.ind_order;
|
||||
user.date_reg = recextra.date_reg;
|
||||
if (recextra.aportador_solidario_name_surname)
|
||||
user.aportador_solidario_nome_completo = recextra.aportador_solidario_name_surname;
|
||||
else
|
||||
user.aportador_solidario_nome_completo = recextra.aportador_solidario_originale_name_surname;
|
||||
|
||||
user.aportador_solidario_ind_order = recextra.aportador_solidario_ind_order;
|
||||
|
||||
const useraportador = await ExtraList.findByIndOrder(user.idapp, user.aportador_solidario_ind_order);
|
||||
if (useraportador)
|
||||
user.aportador_solidario = useraportador.username;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return await user.save()
|
||||
.then(async () => {
|
||||
return await User.findByUsername(user.idapp, user.username)
|
||||
.then((usertrovato) => {
|
||||
|
||||
// tools.mylog("TROVATO USERNAME ? ", user.username, usertrovato);
|
||||
@@ -84,18 +121,30 @@ router.post('/', async (req, res) => {
|
||||
res.status(400).send();
|
||||
return 0;
|
||||
}
|
||||
}).then((token) => {
|
||||
})
|
||||
.then(async (token) => {
|
||||
// tools.mylog("passo il TOKEN: ", token);
|
||||
res.header('x-auth', token).send(user);
|
||||
|
||||
if (recextra) {
|
||||
recextra.registered = true;
|
||||
recextra.username = user.username;
|
||||
await recextra.save();
|
||||
|
||||
await User.fixUsername(user.idapp, user.ind_order, user.username);
|
||||
}
|
||||
return token;
|
||||
})
|
||||
.then(async (token) => {
|
||||
|
||||
// tools.mylog("LINKREG = " + user.linkreg);
|
||||
// Invia un'email all'utente
|
||||
// tools.mylog('process.env.TESTING_ON', process.env.TESTING_ON);
|
||||
console.log('res.locale', res.locale);
|
||||
if (!tools.testing()) {
|
||||
return sendemail.sendEmail_Registration(user.lang, user.email, user, user.idapp, user.linkreg);
|
||||
await sendemail.sendEmail_Registration(user.lang, user.email, user, user.idapp, user.linkreg);
|
||||
}
|
||||
|
||||
res.header('x-auth', token).send(user);
|
||||
return true;
|
||||
});
|
||||
}).catch((e) => {
|
||||
res.status(400).send(e);
|
||||
@@ -158,7 +207,7 @@ router.post('/login', (req, res) => {
|
||||
|
||||
User.findByCredentials(user.idapp, user.username, user.password)
|
||||
.then((user) => {
|
||||
tools.mylog("CREDENZIALI ! ");
|
||||
// tools.mylog("CREDENZIALI ! ");
|
||||
if (!user) {
|
||||
tools.mylogshow("NOT FOUND !");
|
||||
res.status(404).send({ code: server_constants.RIS_CODE_LOGIN_ERR });
|
||||
@@ -208,7 +257,7 @@ router.post('/login', (req, res) => {
|
||||
});
|
||||
// tools.mylog("TROVATOOO!");
|
||||
|
||||
tools.mylog('FINE LOGIN')
|
||||
// tools.mylog('FINE LOGIN')
|
||||
});
|
||||
}
|
||||
})
|
||||
@@ -220,7 +269,7 @@ router.post('/login', (req, res) => {
|
||||
});
|
||||
|
||||
router.delete('/me/token', authenticate, (req, res) => {
|
||||
tools.mylog("TOKENREM = " + req.token);
|
||||
// tools.mylog("TOKENREM = " + req.token);
|
||||
req.user.removeToken(req.token).then(() => {
|
||||
res.status(200).send();
|
||||
}, () => {
|
||||
@@ -239,5 +288,17 @@ router.post('/setperm', authenticate, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
router.post('/import_extralist', async (req, res) => {
|
||||
|
||||
const strdata = req.body.strdata;
|
||||
idapp = req.body.idapp;
|
||||
locale = req.body.locale;
|
||||
|
||||
const ris = await ExtraList.ImportData(locale, idapp, strdata);
|
||||
console.log('ris', ris);
|
||||
|
||||
res.send(ris);
|
||||
});
|
||||
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -52,6 +52,7 @@ const subscribe_router = require('./router/subscribe_router');
|
||||
const sendmsg_router = require('./router/sendmsg_router');
|
||||
const email_router = require('./router/email_router');
|
||||
const todos_router = require('./router/todos_router');
|
||||
const test_router = require('./router/test_router');
|
||||
const projects_router = require('./router/projects_router');
|
||||
const users_router = require('./router/users_router');
|
||||
const admin_router = require('./router/admin_router');
|
||||
@@ -112,6 +113,7 @@ app.use('/dashboard', dashboard_router);
|
||||
app.use('/event', myevent_router);
|
||||
app.use('/email', email_router);
|
||||
app.use('/todos', todos_router);
|
||||
app.use('/test', test_router);
|
||||
app.use('/projects', projects_router);
|
||||
app.use('/users', users_router);
|
||||
app.use('/admin', admin_router);
|
||||
@@ -219,7 +221,7 @@ function startserv() {
|
||||
|
||||
|
||||
// Check if is Empty (new Server Data)
|
||||
cfgserver.count(function (err, count) {
|
||||
cfgserver.countDocuments(function (err, count) {
|
||||
if (!err && count === 0) {
|
||||
populateDBadmin();
|
||||
}
|
||||
|
||||
@@ -423,7 +423,9 @@ function getclTelegByidapp(idapp) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (const idapp of appTelegram) {
|
||||
if (!tools.testing()) {
|
||||
console.log('TELEGRAM STARTING.... ');
|
||||
for (const idapp of appTelegram) {
|
||||
|
||||
const token = tools.getTelegramKeyByIdApp(idapp);
|
||||
// console.log('idapp', idapp, 'token', token);
|
||||
@@ -482,5 +484,6 @@ for (const idapp of appTelegram) {
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ const userjson = JSON.stringify(users[0]);
|
||||
|
||||
const todos = [{
|
||||
_id: new ObjectID(),
|
||||
category: "personal",
|
||||
// category: "personal",
|
||||
statustodo: 0,
|
||||
completed_at: new Date(),
|
||||
created_at: new Date(),
|
||||
@@ -96,7 +96,7 @@ const todos = [{
|
||||
userId: users[0]._id
|
||||
}, {
|
||||
_id: new ObjectID(),
|
||||
category: "personal",
|
||||
// category: "personal",
|
||||
statustodo: 0,
|
||||
completed_at: new Date(),
|
||||
created_at: new Date(),
|
||||
@@ -112,7 +112,7 @@ const todos = [{
|
||||
userId: users[0]._id
|
||||
}, {
|
||||
_id: new ObjectID(),
|
||||
category: "personal",
|
||||
// category: "personal",
|
||||
statustodo: 0,
|
||||
completed_at: new Date(),
|
||||
created_at: new Date(),
|
||||
@@ -127,7 +127,7 @@ const todos = [{
|
||||
progress: 0,
|
||||
}, { // RECORD CHE VERRA' UTILIZZATO PER AGGIUNGERE UN NUOVO TASK
|
||||
_id: new ObjectID(),
|
||||
category: "personal",
|
||||
// category: "personal",
|
||||
statustodo: 0,
|
||||
completed_at: new Date(),
|
||||
created_at: new Date(),
|
||||
@@ -148,8 +148,8 @@ const populateTodos = (done) => {
|
||||
Todo.deleteMany({})
|
||||
.then(() => {
|
||||
|
||||
var TodoOne = new Todo(todos[0]).save();
|
||||
var TodoTwo = new Todo(todos[1]).save();
|
||||
const TodoOne = new Todo(todos[0]).save();
|
||||
const TodoTwo = new Todo(todos[1]).save();
|
||||
|
||||
return Promise.all([TodoOne, TodoTwo])
|
||||
}).then(() => {
|
||||
|
||||
@@ -58,7 +58,7 @@ if (testsingolo) {
|
||||
})
|
||||
.expect(200)
|
||||
.expect((res) => {
|
||||
expect(res.headers['x-auth']).toExist();
|
||||
expect(res.headers['x-auth']).toBeTruthy();
|
||||
})
|
||||
.end((err, res) => {
|
||||
if (err) {
|
||||
@@ -66,7 +66,7 @@ if (testsingolo) {
|
||||
}
|
||||
|
||||
User.findById(users[0]._id).then((user) => {
|
||||
expect(user.tokens[0]).toInclude({
|
||||
expect(user.tokens[0]).toContain({
|
||||
access: 'auth',
|
||||
// token: res.headers['x-auth'],
|
||||
date_login: date_login
|
||||
@@ -86,8 +86,8 @@ if (testsingolo) {
|
||||
.send(users[IndexUserToCreate])
|
||||
.expect(200)
|
||||
.expect((res) => {
|
||||
expect(res.headers['x-auth']).toExist();
|
||||
expect(res.body._id).toExist();
|
||||
expect(res.headers['x-auth']).toBeTruthy();
|
||||
expect(res.body._id).toBeTruthy();
|
||||
expect(res.body.email).toBe(users[IndexUserToCreate].email);
|
||||
expect(res.body.username).toBe(users[IndexUserToCreate].username);
|
||||
expect(res.body.name).toBe(users[IndexUserToCreate].name);
|
||||
@@ -100,7 +100,7 @@ if (testsingolo) {
|
||||
}
|
||||
|
||||
User.findOne({ email: users[IndexUserToCreate].email }).then((user) => {
|
||||
expect(user).toExist();
|
||||
expect(user).toBeTruthy();
|
||||
done();
|
||||
}).catch((e) => done(e));
|
||||
});
|
||||
@@ -126,10 +126,10 @@ if (testsingolo) {
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /users/myusername', () => {
|
||||
describe('GET /users/idapp/myusername', () => {
|
||||
it('should return 200 if myusername exist', (done) => {
|
||||
request(app)
|
||||
.get('/users/' + users[0].username)
|
||||
.get('/users/' + users[0].idapp + '/' + users[0].username)
|
||||
// .set('x-auth', users[0].tokens[0].token)
|
||||
.expect(200)
|
||||
.end(done);
|
||||
@@ -137,7 +137,7 @@ if (testsingolo) {
|
||||
|
||||
it('should return 404 if myusername doesn\'t exist', (done) => {
|
||||
request(app)
|
||||
.get('/users/' + users[0].username + 'pippo')
|
||||
.get('/users/' + users[0].idapp + '/' + users[0].username + 'pippo')
|
||||
.expect(404)
|
||||
.end(done);
|
||||
});
|
||||
@@ -157,7 +157,7 @@ if (testsingolo) {
|
||||
})
|
||||
.expect(200)
|
||||
.expect((res) => {
|
||||
expect(res.headers['x-auth']).toExist();
|
||||
expect(res.headers['x-auth']).toBeTruthy();
|
||||
})
|
||||
.end((err, res) => {
|
||||
if (err) {
|
||||
@@ -165,10 +165,12 @@ if (testsingolo) {
|
||||
}
|
||||
|
||||
User.findById(users[0]._id).then((user) => {
|
||||
expect(user.tokens[0]).toInclude({
|
||||
expect(user.tokens[0]).toContain({
|
||||
_id: user.tokens[0]._id,
|
||||
access: 'auth',
|
||||
// token: res.headers['x-auth'],
|
||||
date_login: date_login
|
||||
browser: useragent,
|
||||
date_login: date_login,
|
||||
token: users[0].tokens[0].token,
|
||||
});
|
||||
done();
|
||||
}).catch((e) => done(e));
|
||||
@@ -184,7 +186,7 @@ if (testsingolo) {
|
||||
})
|
||||
.expect(400)
|
||||
.expect((res) => {
|
||||
expect(res.headers['x-auth']).toNotExist();
|
||||
expect(res.headers['x-auth']).not.toBeTruthy();
|
||||
})
|
||||
.end((err, res) => {
|
||||
if (err) {
|
||||
@@ -208,7 +210,7 @@ if (testsingolo) {
|
||||
.send()
|
||||
.expect(200)
|
||||
.expect((res) => {
|
||||
expect(res.headers['x-auth']).toNotExist();
|
||||
expect(res.headers['x-auth']).not.toBeTruthy();
|
||||
})
|
||||
.end((err, res) => {
|
||||
if (err) {
|
||||
@@ -291,7 +293,7 @@ if (testsingolo) {
|
||||
describe('GET /todos', () => {
|
||||
it('should get all todos', (done) => {
|
||||
request(app)
|
||||
.get(`/todos/${users[0]._id }`)
|
||||
.get(`/todos/`)
|
||||
.set('x-auth', users[0].tokens[0].token)
|
||||
.expect(200)
|
||||
.expect((res) => {
|
||||
@@ -309,8 +311,8 @@ if (testsingolo) {
|
||||
.set('x-auth', users[0].tokens[0].token)
|
||||
.expect(200)
|
||||
.expect((res) => {
|
||||
let miores = res
|
||||
let miadescr = miores.body.todos[0].descr
|
||||
let miores = res;
|
||||
let miadescr = miores.body.todos[0].descr;
|
||||
expect(res.body.todos.length).toBe(2);
|
||||
expect(miadescr).toBe(todos[0].descr);
|
||||
})
|
||||
@@ -365,7 +367,7 @@ if (testsingolo) {
|
||||
}
|
||||
|
||||
Todo.findById(hexId).then((todo) => {
|
||||
expect(todo).toNotExist();
|
||||
expect(todo).not.toBeTruthy();
|
||||
done();
|
||||
}).catch((e) => done(e));
|
||||
});
|
||||
|
||||
@@ -41,6 +41,8 @@ module.exports = {
|
||||
|
||||
LANGADMIN: 'it',
|
||||
|
||||
APORTADOR_NONE: '------',
|
||||
|
||||
TYPE_PROJECT: 1,
|
||||
TYPE_TODO: 2,
|
||||
|
||||
@@ -480,7 +482,7 @@ module.exports = {
|
||||
{
|
||||
$project: {
|
||||
count: 1,
|
||||
rows: { $slice: ['$results', params.startRow, params.endRow] }
|
||||
rows: { $slice: ['$results', params.startRow, params.endRow - params.startRow] }
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -513,6 +515,41 @@ module.exports = {
|
||||
});
|
||||
|
||||
},
|
||||
async DuplicateAllRecords(mythistable, idapporig, idappdest) {
|
||||
console.log(mythistable.name);
|
||||
|
||||
const numrec = await mythistable.findAllIdApp(idappdest).then((arrrec) => {
|
||||
if (arrrec && arrrec.length > 1) {
|
||||
return arrrec.length; // Has Already set
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
// Before check if exist more than 1 record in the destination,
|
||||
// if Yes don't copy
|
||||
if (numrec <= 0) {
|
||||
return await mythistable.findAllIdApp(idapporig).then(async (arrrec) => {
|
||||
let num = 0;
|
||||
|
||||
for (let ind = 0; ind < arrrec.length; ind++) {
|
||||
let newrec = new mythistable(arrrec[ind]._doc);
|
||||
newrec._id = new ObjectID();
|
||||
newrec.idapp = idappdest;
|
||||
|
||||
await newrec.save((err, rec) => {
|
||||
if (rec) {
|
||||
num++;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
return num;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
isBitActive(bit, whattofind) {
|
||||
return ((bit & whattofind) === whattofind)
|
||||
@@ -658,4 +695,38 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
extractNameAndSurnameByComplete(name_complete) {
|
||||
const suffissoCognome = ['Del', 'La', 'De', 'Lo'];
|
||||
|
||||
let campi = name_complete.split(" ");
|
||||
let namesurname = {
|
||||
name: '',
|
||||
surname: '',
|
||||
};
|
||||
|
||||
if (campi.length === 2) {
|
||||
namesurname.name = campi[0];
|
||||
namesurname.surname = campi[1];
|
||||
}else if (campi.length === 3) {
|
||||
if (suffissoCognome.includes(campi[1])) {
|
||||
namesurname.name = campi[0];
|
||||
namesurname.surname = campi[1] + " " + campi[2];
|
||||
} else {
|
||||
namesurname.name = campi[0] + " " + campi[1];
|
||||
namesurname.surname = campi[2];
|
||||
}
|
||||
}else if (campi.length === 4) {
|
||||
namesurname.name = campi[0] + " " + campi[1];
|
||||
namesurname.surname = campi[2] + " " + campi[3];
|
||||
}else if (campi.length > 4) {
|
||||
namesurname.name = campi[0] + " " + campi[1];
|
||||
namesurname.surname = " " + campi[2];
|
||||
for (const ind = 3; ind < campi.length; ind++) {
|
||||
namesurname.surname += " " + campi[ind];
|
||||
}
|
||||
}
|
||||
|
||||
return namesurname
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ module.exports = Object.freeze({
|
||||
RIS_CODE_EMAIL_ALREADY_VERIFIED: -5,
|
||||
RIS_CODE_EMAIL_VERIFIED: 1,
|
||||
|
||||
RIS_CODE_USER_EXTRALIST_NOTFOUND: -70,
|
||||
RIS_CODE_USERNAME_ALREADY_EXIST: -60,
|
||||
RIS_CODE_EMAIL_ALREADY_EXIST: -50,
|
||||
RIS_CODE_EMAIL_NOT_SENT: -40,
|
||||
|
||||
Reference in New Issue
Block a user