- corretto problema ROGNOSO : Risolvere la questione "Sessioni multiple", se apro 2 browser l'ultimo va a cancellare il precedente, e mi da errore di email non valida !
Il problema era sulla fetch nel service worker, gestita in quel modo personalizzato, andava in conflitto, non tenendo le chiamate bloccanti, ma uscivano prima che arrivasse la risposta del server. - Per chi è da tanto che non si collega a RISO, compare "Email non verificata"... (si risolve chiudendo su ESCI e riloggandosi)... però andrebbe sistemata. (stesso problema di prima).
This commit is contained in:
@@ -31,6 +31,7 @@
|
|||||||
"ejs": "^3.1.10",
|
"ejs": "^3.1.10",
|
||||||
"email-templates": "^12.0.2",
|
"email-templates": "^12.0.2",
|
||||||
"express": "^4.21.2",
|
"express": "^4.21.2",
|
||||||
|
"fast-csv": "^5.0.5",
|
||||||
"formidable": "^3.5.2",
|
"formidable": "^3.5.2",
|
||||||
"ghostscript4js": "^3.2.3",
|
"ghostscript4js": "^3.2.3",
|
||||||
"helmet": "^8.1.0",
|
"helmet": "^8.1.0",
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ const authenticateMiddleware = async (req, res, next, withUser = false, lean = f
|
|||||||
const refreshToken = req.header('x-refrtok');
|
const refreshToken = req.header('x-refrtok');
|
||||||
const logPrefix = noError ? (withUser ? (lean ? 'WITHUSERLEAN' : 'WITHUSER') : 'NOERROR') : 'AUTH';
|
const logPrefix = noError ? (withUser ? (lean ? 'WITHUSERLEAN' : 'WITHUSER') : 'NOERROR') : 'AUTH';
|
||||||
|
|
||||||
|
// console.log('authenticateMiddleware, token:', token, ' refreshToken:', refreshToken, 'withUser:', withUser, 'noError:', noError);
|
||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
req.user = null;
|
req.user = null;
|
||||||
req.token = null;
|
req.token = null;
|
||||||
@@ -28,10 +30,14 @@ const authenticateMiddleware = async (req, res, next, withUser = false, lean = f
|
|||||||
|
|
||||||
const user = await User.findByToken(token, 'auth', false, withUser, lean);
|
const user = await User.findByToken(token, 'auth', false, withUser, lean);
|
||||||
|
|
||||||
|
req.statuscode2 = null;
|
||||||
|
|
||||||
if (user.code !== server_constants.RIS_CODE_OK) {
|
if (user.code !== server_constants.RIS_CODE_OK) {
|
||||||
req.user = null;
|
req.user = null;
|
||||||
req.token = null;
|
req.token = null;
|
||||||
req.code = user.code;
|
req.code = user.code;
|
||||||
|
if (user.code === server_constants.RIS_CODE_HTTP_FORBIDDEN_TOKEN_EXPIRED)
|
||||||
|
console.log('TOKEN SCADUTO!');
|
||||||
} else {
|
} else {
|
||||||
req.user = user.user;
|
req.user = user.user;
|
||||||
req.token = token;
|
req.token = token;
|
||||||
@@ -42,7 +48,9 @@ const authenticateMiddleware = async (req, res, next, withUser = false, lean = f
|
|||||||
if (user.code === server_constants.RIS_CODE_HTTP_FORBIDDEN_TOKEN_EXPIRED) {
|
if (user.code === server_constants.RIS_CODE_HTTP_FORBIDDEN_TOKEN_EXPIRED) {
|
||||||
console.log(` TOKEN SCADUTO ! `);
|
console.log(` TOKEN SCADUTO ! `);
|
||||||
if (noError) {
|
if (noError) {
|
||||||
|
req.statuscode2 = server_constants.RIS_CODE_HTTP_FORBIDDEN_TOKEN_EXPIRED;
|
||||||
return next()
|
return next()
|
||||||
|
// return res.status(server_constants.RIS_CODE_HTTP_FORBIDDEN_TOKEN_EXPIRED).send();
|
||||||
} else {
|
} else {
|
||||||
return res.status(server_constants.RIS_CODE_HTTP_FORBIDDEN_TOKEN_EXPIRED).send();
|
return res.status(server_constants.RIS_CODE_HTTP_FORBIDDEN_TOKEN_EXPIRED).send();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -253,11 +253,15 @@ CatalogSchema.statics.getCatalogById = async function (id) {
|
|||||||
model: 'Gasordine',
|
model: 'Gasordine',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// controlla prima se nella lista ci sono dei product che non esistono piu allora li devi rimuovere !
|
// controlla prima se nella lista ci sono dei product che non esistono piu allora li devi rimuovere !
|
||||||
for (const catalog of arrrec) {
|
for (const catalog of arrrec) {
|
||||||
|
let old_lista = [...catalog.lista_prodotti];
|
||||||
|
|
||||||
|
let nuova_lista = [...catalog.lista_prodotti];
|
||||||
|
|
||||||
const originalLength = catalog.lista_prodotti.length;
|
const originalLength = catalog.lista_prodotti.length;
|
||||||
catalog.lista_prodotti = catalog.lista_prodotti.filter(
|
nuova_lista = nuova_lista.filter(
|
||||||
(product) =>
|
(product) =>
|
||||||
product.productInfo &&
|
product.productInfo &&
|
||||||
product.productInfo.code &&
|
product.productInfo.code &&
|
||||||
@@ -266,11 +270,21 @@ CatalogSchema.statics.getCatalogById = async function (id) {
|
|||||||
product.productInfo.imagefile !== 'noimg.jpg' &&
|
product.productInfo.imagefile !== 'noimg.jpg' &&
|
||||||
!product.delete
|
!product.delete
|
||||||
);
|
);
|
||||||
if (catalog.lista_prodotti.length !== originalLength) {
|
|
||||||
await catalog.save();
|
// Se la nuova lista è diversa da quella precedente di più del 10%, allora non aggiorna, perché potrebbe esserci un problema
|
||||||
|
let differencePercentage = (100 * Math.abs(originalLength - nuova_lista.length)) / originalLength;
|
||||||
|
if (differencePercentage < 10) {
|
||||||
|
// Aggiorno la lista solo se è cambiata poco
|
||||||
|
// confronta l'array nuova_lista con l'array catalog.lista_prodotti
|
||||||
|
let differents = tools.areDifferentProduct(catalog.lista_prodotti, nuova_lista);
|
||||||
|
|
||||||
|
if (differents) {
|
||||||
|
// aggiorna la lista
|
||||||
|
catalog.lista_prodotti = nuova_lista;
|
||||||
|
await catalog.save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const transformedArrRec = arrrec.map((catalog) => ({
|
const transformedArrRec = arrrec.map((catalog) => ({
|
||||||
...catalog.toObject(), // Converte il documento Mongoose in un oggetto JavaScript puro
|
...catalog.toObject(), // Converte il documento Mongoose in un oggetto JavaScript puro
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const { MyGroup } = require('./mygroup');
|
|||||||
const tableModel = shared_consts.TABLES_MYBACHECAS;
|
const tableModel = shared_consts.TABLES_MYBACHECAS;
|
||||||
|
|
||||||
// Resolving error Unknown modifier: $pushAll
|
// Resolving error Unknown modifier: $pushAll
|
||||||
mongoose.plugin(schema => {
|
mongoose.plugin((schema) => {
|
||||||
schema.options.usePushEach = true;
|
schema.options.usePushEach = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -43,32 +43,37 @@ const MyBachecaSchema = new Schema({
|
|||||||
idStatusSkill: [
|
idStatusSkill: [
|
||||||
{
|
{
|
||||||
type: Number,
|
type: Number,
|
||||||
}],
|
},
|
||||||
|
],
|
||||||
idContribType: [
|
idContribType: [
|
||||||
{
|
{
|
||||||
type: String,
|
type: String,
|
||||||
}],
|
},
|
||||||
|
],
|
||||||
idCity: [
|
idCity: [
|
||||||
{
|
{
|
||||||
type: Number,
|
type: Number,
|
||||||
}],
|
},
|
||||||
|
],
|
||||||
dateTimeStart: {
|
dateTimeStart: {
|
||||||
type: Date,
|
type: Date,
|
||||||
},
|
},
|
||||||
dateTimeEnd: {
|
dateTimeEnd: {
|
||||||
type: Date,
|
type: Date,
|
||||||
|
required: false, // non obbligatorio
|
||||||
|
default: null, // valore predefinito esplicito (opzionale)
|
||||||
},
|
},
|
||||||
organisedBy: {
|
organisedBy: {
|
||||||
type: String
|
type: String,
|
||||||
},
|
},
|
||||||
contact_phone: {
|
contact_phone: {
|
||||||
type: String
|
type: String,
|
||||||
},
|
},
|
||||||
contact_email: {
|
contact_email: {
|
||||||
type: String
|
type: String,
|
||||||
},
|
},
|
||||||
contact_telegram: {
|
contact_telegram: {
|
||||||
type: String
|
type: String,
|
||||||
},
|
},
|
||||||
address: {
|
address: {
|
||||||
type: String,
|
type: String,
|
||||||
@@ -103,7 +108,8 @@ const MyBachecaSchema = new Schema({
|
|||||||
description: {
|
description: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
}],
|
},
|
||||||
|
],
|
||||||
note: {
|
note: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
@@ -121,15 +127,17 @@ const MyBachecaSchema = new Schema({
|
|||||||
date_updated: {
|
date_updated: {
|
||||||
type: Date,
|
type: Date,
|
||||||
},
|
},
|
||||||
|
link_conference: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
...Reaction.getFieldsForReactions(),
|
...Reaction.getFieldsForReactions(),
|
||||||
...tools.getFieldsForAnnunci()
|
...tools.getFieldsForAnnunci(),
|
||||||
});
|
});
|
||||||
|
|
||||||
MyBachecaSchema.pre('save', async function (next) {
|
MyBachecaSchema.pre('save', async function (next) {
|
||||||
if (this.isNew) {
|
if (this.isNew) {
|
||||||
if (!this.date_created)
|
if (!this.date_created) this.date_created = new Date();
|
||||||
this.date_created = new Date();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
@@ -138,13 +146,9 @@ MyBachecaSchema.pre('save', async function (next) {
|
|||||||
MyBachecaSchema.statics.findAllIdApp = async function (idapp) {
|
MyBachecaSchema.statics.findAllIdApp = async function (idapp) {
|
||||||
const MyBacheca = this;
|
const MyBacheca = this;
|
||||||
|
|
||||||
const query = [
|
const query = [{ $match: { idapp } }, { $sort: { descr: 1 } }];
|
||||||
{ $match: { idapp } },
|
|
||||||
{ $sort: { descr: 1 } },
|
|
||||||
];
|
|
||||||
|
|
||||||
return await MyBacheca.aggregate(query);
|
return await MyBacheca.aggregate(query);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
MyBachecaSchema.statics.getFieldsForSearch = function () {
|
MyBachecaSchema.statics.getFieldsForSearch = function () {
|
||||||
@@ -160,7 +164,6 @@ MyBachecaSchema.statics.getFieldsLastForSearch = function () {
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
MyBachecaSchema.statics.executeQueryTable = function (idapp, params, user) {
|
MyBachecaSchema.statics.executeQueryTable = function (idapp, params, user) {
|
||||||
params.fieldsearch = this.getFieldsForSearch();
|
params.fieldsearch = this.getFieldsForSearch();
|
||||||
params.fieldsearch_last = this.getFieldsLastForSearch();
|
params.fieldsearch_last = this.getFieldsLastForSearch();
|
||||||
@@ -184,16 +187,14 @@ MyBachecaSchema.statics.executeQueryTable = function (idapp, params, user) {
|
|||||||
MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||||
const MyBacheca = this;
|
const MyBacheca = this;
|
||||||
|
|
||||||
|
|
||||||
let myparsid = {
|
let myparsid = {
|
||||||
'_id': id,
|
_id: id,
|
||||||
idapp,
|
idapp,
|
||||||
};
|
};
|
||||||
|
|
||||||
let query = [
|
let query = [
|
||||||
{
|
{
|
||||||
$match:
|
$match: myparsid,
|
||||||
myparsid,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$sort: {
|
$sort: {
|
||||||
@@ -202,28 +203,25 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
$addFields: {
|
$addFields: {
|
||||||
'myId1': {
|
myId1: {
|
||||||
'$toObjectId': '$userId',
|
$toObjectId: '$userId',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'$lookup': {
|
$lookup: {
|
||||||
'from': 'users',
|
from: 'users',
|
||||||
'localField': 'myId1',
|
localField: 'myId1',
|
||||||
'foreignField': '_id',
|
foreignField: '_id',
|
||||||
'as': 'user',
|
as: 'user',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'$replaceRoot': {
|
$replaceRoot: {
|
||||||
'newRoot': {
|
newRoot: {
|
||||||
'$mergeObjects': [
|
$mergeObjects: [
|
||||||
{
|
{
|
||||||
'$arrayElemAt': [
|
$arrayElemAt: ['$user', 0],
|
||||||
'$user',
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
'$$ROOT',
|
'$$ROOT',
|
||||||
],
|
],
|
||||||
@@ -234,22 +232,19 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
|||||||
$project: shared_consts.getProjectForAll({}, tableModel),
|
$project: shared_consts.getProjectForAll({}, tableModel),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'$lookup': {
|
$lookup: {
|
||||||
'from': 'skills',
|
from: 'skills',
|
||||||
'localField': 'idSkill',
|
localField: 'idSkill',
|
||||||
'foreignField': '_id',
|
foreignField: '_id',
|
||||||
'as': 'recSkill',
|
as: 'recSkill',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'$replaceRoot': {
|
$replaceRoot: {
|
||||||
'newRoot': {
|
newRoot: {
|
||||||
'$mergeObjects': [
|
$mergeObjects: [
|
||||||
{
|
{
|
||||||
'$arrayElemAt': [
|
$arrayElemAt: ['$recSkill', 0],
|
||||||
'$recSkill',
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
'$$ROOT',
|
'$$ROOT',
|
||||||
],
|
],
|
||||||
@@ -260,22 +255,19 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
|||||||
$project: shared_consts.getProjectForAll({}, tableModel),
|
$project: shared_consts.getProjectForAll({}, tableModel),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'$lookup': {
|
$lookup: {
|
||||||
'from': 'sectors',
|
from: 'sectors',
|
||||||
'localField': 'idSector',
|
localField: 'idSector',
|
||||||
'foreignField': '_id',
|
foreignField: '_id',
|
||||||
'as': 'sector',
|
as: 'sector',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'$replaceRoot': {
|
$replaceRoot: {
|
||||||
'newRoot': {
|
newRoot: {
|
||||||
'$mergeObjects': [
|
$mergeObjects: [
|
||||||
{
|
{
|
||||||
'$arrayElemAt': [
|
$arrayElemAt: ['$sector', 0],
|
||||||
'$sector',
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
'$$ROOT',
|
'$$ROOT',
|
||||||
],
|
],
|
||||||
@@ -284,10 +276,10 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
'from': 'mygroups',
|
from: 'mygroups',
|
||||||
'localField': 'groupname',
|
localField: 'groupname',
|
||||||
'foreignField': 'groupname',
|
foreignField: 'groupname',
|
||||||
'as': 'mygrp',
|
as: 'mygrp',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -308,14 +300,11 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
|||||||
},
|
},
|
||||||
},*/
|
},*/
|
||||||
{
|
{
|
||||||
'$replaceRoot': {
|
$replaceRoot: {
|
||||||
'newRoot': {
|
newRoot: {
|
||||||
'$mergeObjects': [
|
$mergeObjects: [
|
||||||
{
|
{
|
||||||
'$arrayElemAt': [
|
$arrayElemAt: ['$MyBacheca', 0],
|
||||||
'$MyBacheca',
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
'$$ROOT',
|
'$$ROOT',
|
||||||
],
|
],
|
||||||
@@ -326,22 +315,19 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
|||||||
$project: shared_consts.getProjectForAll({}, tableModel),
|
$project: shared_consts.getProjectForAll({}, tableModel),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'$lookup': {
|
$lookup: {
|
||||||
'from': 'cities',
|
from: 'cities',
|
||||||
'localField': 'idCity',
|
localField: 'idCity',
|
||||||
'foreignField': '_id',
|
foreignField: '_id',
|
||||||
'as': 'mycities',
|
as: 'mycities',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'$replaceRoot': {
|
$replaceRoot: {
|
||||||
'newRoot': {
|
newRoot: {
|
||||||
'$mergeObjects': [
|
$mergeObjects: [
|
||||||
{
|
{
|
||||||
'$arrayElemAt': [
|
$arrayElemAt: ['$mycities', 0],
|
||||||
'$mycities',
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
'$$ROOT',
|
'$$ROOT',
|
||||||
],
|
],
|
||||||
@@ -370,20 +356,18 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
MyBachecaSchema.statics.getCompleteRecord = function (idapp, id) {
|
MyBachecaSchema.statics.getCompleteRecord = function (idapp, id) {
|
||||||
const MyBacheca = this;
|
const MyBacheca = this;
|
||||||
|
|
||||||
return MyBacheca.getMyRecById(idapp, id);
|
return MyBacheca.getMyRecById(idapp, id);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const MyBacheca = mongoose.model('MyBacheca', MyBachecaSchema);
|
const MyBacheca = mongoose.model('MyBacheca', MyBachecaSchema);
|
||||||
|
|
||||||
MyBacheca.createIndexes()
|
MyBacheca.createIndexes()
|
||||||
.then(() => { })
|
.then(() => {})
|
||||||
.catch((err) => { throw err; });
|
.catch((err) => {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = { MyBacheca };
|
module.exports = { MyBacheca };
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ const MyEventSchema = new Schema({
|
|||||||
},
|
},
|
||||||
dateTimeEnd: {
|
dateTimeEnd: {
|
||||||
type: Date,
|
type: Date,
|
||||||
|
required: false, // non obbligatorio
|
||||||
|
default: null, // valore predefinito esplicito (opzionale)
|
||||||
},
|
},
|
||||||
bgcolor: {
|
bgcolor: {
|
||||||
type: String,
|
type: String,
|
||||||
|
|||||||
@@ -551,7 +551,6 @@ UserSchema.methods.toJSON = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
UserSchema.methods.generateAuthToken = function (req) {
|
UserSchema.methods.generateAuthToken = function (req) {
|
||||||
// console.log("GENERA TOKEN : ");
|
|
||||||
const user = this;
|
const user = this;
|
||||||
|
|
||||||
const useragent = req.get('User-Agent');
|
const useragent = req.get('User-Agent');
|
||||||
@@ -568,34 +567,37 @@ UserSchema.methods.generateAuthToken = function (req) {
|
|||||||
|
|
||||||
if (attiva_scadenza)
|
if (attiva_scadenza)
|
||||||
token = jwt
|
token = jwt
|
||||||
.sign({ _id: prova, smart: user._id.toHexString(), access, un: user.username }, process.env.SIGNCODE, {
|
.sign({ _id: user._id.toHexString(), access, un: user.username }, process.env.SIGNCODE, {
|
||||||
expiresIn: numsec,
|
expiresIn: numsec,
|
||||||
})
|
})
|
||||||
.toString();
|
.toString();
|
||||||
else
|
else
|
||||||
token = jwt
|
token = jwt
|
||||||
.sign({ _id: prova, smart: user._id.toHexString(), access, un: user.username }, process.env.SIGNCODE)
|
.sign({ _id: user._id.toHexString(), access, un: user.username }, process.env.SIGNCODE)
|
||||||
.toString();
|
.toString();
|
||||||
|
|
||||||
const refreshToken = jwt
|
const refreshToken = jwt
|
||||||
.sign({ _id: prova, smart: user._id.toHexString(), access, un: user.username }, process.env.SECRK, {
|
.sign({ _id: user._id.toHexString(), access, un: user.username }, process.env.SECRK, {
|
||||||
expiresIn: process.env.REFRESH_TOKEN_LIFE,
|
expiresIn: process.env.REFRESH_TOKEN_LIFE,
|
||||||
})
|
})
|
||||||
.toString();
|
.toString();
|
||||||
const date_login = new Date();
|
const date_login = new Date();
|
||||||
|
|
||||||
// CANCELLA IL PRECEDENTE !
|
// Controlla se il token è già presente per la coppia access-browser
|
||||||
user.tokens = user.tokens.filter(function (tok) {
|
const idx = user.tokens.findIndex((tok) => tok.access === access && tok.browser === browser);
|
||||||
return tok.access !== access || (tok.access === access && tok.browser !== browser);
|
if (idx === -1) {
|
||||||
});
|
user.tokens.push({ access, browser, token, date_login, refreshToken });
|
||||||
|
} else {
|
||||||
user.tokens.push({ access, browser, token, date_login, refreshToken });
|
// Se il token esiste già, sostituisce il valore vecchio con il nuovo
|
||||||
|
user.tokens[idx] = { access, browser, token, date_login, refreshToken };
|
||||||
|
}
|
||||||
|
|
||||||
user.lasttimeonline = new Date();
|
user.lasttimeonline = new Date();
|
||||||
|
|
||||||
return user
|
return user
|
||||||
.save()
|
.save()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
console.log('########## HO CREATO UN NUOVO TOKEN E REFRESHTOKEN !!!!! ----------- ');
|
||||||
return { token, refreshToken };
|
return { token, refreshToken };
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -811,7 +813,7 @@ UserSchema.statics.findByToken = async function (token, typeaccess, con_auth, wi
|
|||||||
if (withlean) {
|
if (withlean) {
|
||||||
user = await User.findOne(
|
user = await User.findOne(
|
||||||
{
|
{
|
||||||
_id: decoded.smart,
|
_id: decoded._id,
|
||||||
tokens: {
|
tokens: {
|
||||||
$elemMatch: {
|
$elemMatch: {
|
||||||
token,
|
token,
|
||||||
@@ -824,7 +826,7 @@ UserSchema.statics.findByToken = async function (token, typeaccess, con_auth, wi
|
|||||||
} else {
|
} else {
|
||||||
user = await User.findOne(
|
user = await User.findOne(
|
||||||
{
|
{
|
||||||
_id: decoded.smart,
|
_id: decoded._id,
|
||||||
tokens: {
|
tokens: {
|
||||||
$elemMatch: {
|
$elemMatch: {
|
||||||
token,
|
token,
|
||||||
@@ -852,7 +854,7 @@ UserSchema.statics.findByToken = async function (token, typeaccess, con_auth, wi
|
|||||||
const start_find = process.hrtime.bigint();
|
const start_find = process.hrtime.bigint();
|
||||||
user = await User.findOne(
|
user = await User.findOne(
|
||||||
{
|
{
|
||||||
_id: decoded.smart,
|
_id: decoded._id,
|
||||||
tokens: {
|
tokens: {
|
||||||
$elemMatch: {
|
$elemMatch: {
|
||||||
token,
|
token,
|
||||||
@@ -893,11 +895,28 @@ UserSchema.statics.findByTokenAnyAccess = function (token) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return User.findOne({
|
return User.findOne({
|
||||||
_id: decoded.smart,
|
_id: decoded._id,
|
||||||
'tokens.token': token,
|
'tokens.token': token,
|
||||||
}).lean();
|
}).lean();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
UserSchema.statics.findByRefreshTokenAnyAccess = function (refreshToken) {
|
||||||
|
const User = this;
|
||||||
|
let decoded;
|
||||||
|
|
||||||
|
try {
|
||||||
|
decoded = jwt.verify(refreshToken, process.env.SECRK);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Err findByRefreshTokenAnyAccess:', e);
|
||||||
|
return Promise.resolve(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return User.findOne({
|
||||||
|
_id: decoded._id,
|
||||||
|
'tokens.refreshToken': refreshToken,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
UserSchema.statics.findByCredentials = async function (idapp, username, password, pwdcrypted) {
|
UserSchema.statics.findByCredentials = async function (idapp, username, password, pwdcrypted) {
|
||||||
const User = this;
|
const User = this;
|
||||||
let pwd = '';
|
let pwd = '';
|
||||||
@@ -1583,7 +1602,7 @@ UserSchema.statics.createNewRequestPwd = function (idapp, email, code) {
|
|||||||
} else {
|
} else {
|
||||||
// Creo il tokenforgot
|
// Creo il tokenforgot
|
||||||
user.tokenforgot = jwt
|
user.tokenforgot = jwt
|
||||||
.sign({ _id: 'prova123##', smart: user._id.toHexString() }, process.env.SIGNCODE)
|
.sign({ _id: user._id.toHexString() }, process.env.SIGNCODE)
|
||||||
.toString();
|
.toString();
|
||||||
user.date_tokenforgot = new Date();
|
user.date_tokenforgot = new Date();
|
||||||
user.tokenforgot_code = 100000 + Math.round(Math.random() * 899999);
|
user.tokenforgot_code = 100000 + Math.round(Math.random() * 899999);
|
||||||
@@ -1621,7 +1640,7 @@ UserSchema.statics.createNewRequestPwdByUsernameAndGetLink = async function (ida
|
|||||||
const prova = 'dasdas1231#11';
|
const prova = 'dasdas1231#11';
|
||||||
// Creo il tokenforgot
|
// Creo il tokenforgot
|
||||||
user.tokenforgot = jwt
|
user.tokenforgot = jwt
|
||||||
.sign({ _id: prova, smart: user._id.toHexString(), ...additionalData }, process.env.SIGNCODE)
|
.sign({ _id: user._id.toHexString(), ...additionalData }, process.env.SIGNCODE)
|
||||||
.toString();
|
.toString();
|
||||||
user.date_tokenforgot = new Date();
|
user.date_tokenforgot = new Date();
|
||||||
user.tokenforgot_code = 100000 + Math.round(Math.random() * 899999);
|
user.tokenforgot_code = 100000 + Math.round(Math.random() * 899999);
|
||||||
|
|||||||
@@ -64,6 +64,14 @@ class CronMod {
|
|||||||
forzaricarica: false,
|
forzaricarica: false,
|
||||||
});
|
});
|
||||||
ris = { mystr };
|
ris = { mystr };
|
||||||
|
} else if (mydata.dbop === 'EsportaInfoProductExtra') {
|
||||||
|
const macro = new Macro(idapp, {});
|
||||||
|
mystr = await macro.EsportaInfoProductExtra();
|
||||||
|
ris = { mystr };
|
||||||
|
} else if (mydata.dbop === 'ImportaInfoProductExtra') {
|
||||||
|
const macro = new Macro(idapp, {});
|
||||||
|
mystr = await macro.ImportaInfoProductExtra();
|
||||||
|
ris = { mystr };
|
||||||
} else if (mydata.dbop === 'ScraperEstraiDatiAmazon-NoUpdate') {
|
} else if (mydata.dbop === 'ScraperEstraiDatiAmazon-NoUpdate') {
|
||||||
mystr = await AmazonBookScraper.ScraperMultipleDataAmazon(idapp, {
|
mystr = await AmazonBookScraper.ScraperMultipleDataAmazon(idapp, {
|
||||||
update: false,
|
update: false,
|
||||||
|
|||||||
@@ -19,6 +19,25 @@ const T_WEB_Ordini = require('../models/t_web_ordini');
|
|||||||
const T_Web_Argomenti = require('../models/t_web_argomenti');
|
const T_Web_Argomenti = require('../models/t_web_argomenti');
|
||||||
const { JobsInProgress } = require('../models/JobsInProgress');
|
const { JobsInProgress } = require('../models/JobsInProgress');
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const csv = require('fast-csv');
|
||||||
|
|
||||||
|
// Mappa i campi semplici (senza prefisso 'productInfo.')
|
||||||
|
const campiProductInfo = [
|
||||||
|
'code',
|
||||||
|
'descr_trafiletto_catalogo',
|
||||||
|
'sottotitolo',
|
||||||
|
'descrizione_completa_macro',
|
||||||
|
'img2',
|
||||||
|
'img3',
|
||||||
|
'img4',
|
||||||
|
'link',
|
||||||
|
'checkout_link',
|
||||||
|
];
|
||||||
|
|
||||||
|
const CSV_PATH = path.resolve(__dirname, '../products.csv');
|
||||||
|
|
||||||
class Macro {
|
class Macro {
|
||||||
constructor(idapp, options) {
|
constructor(idapp, options) {
|
||||||
this.idapp = idapp;
|
this.idapp = idapp;
|
||||||
@@ -445,6 +464,7 @@ class Macro {
|
|||||||
if (recproducts.length > 10 && lavoromassivo && options.rimuovieventualiCancellati) {
|
if (recproducts.length > 10 && lavoromassivo && options.rimuovieventualiCancellati) {
|
||||||
// disattiva dalla tabella product tutti i campi date_updated_fromGM
|
// disattiva dalla tabella product tutti i campi date_updated_fromGM
|
||||||
const result = await Product.updateMany({ idapp: options.idapp }, { $unset: { date_updated_fromGM: null } });
|
const result = await Product.updateMany({ idapp: options.idapp }, { $unset: { date_updated_fromGM: null } });
|
||||||
|
|
||||||
let quanti_rimossi = result.modifiedCount;
|
let quanti_rimossi = result.modifiedCount;
|
||||||
console.log(`Sbianca date_updated_fromGM da Product: (${quanti_rimossi} su ${result.matchedCount})`);
|
console.log(`Sbianca date_updated_fromGM da Product: (${quanti_rimossi} su ${result.matchedCount})`);
|
||||||
rimuoviTabellePerIniziare = true;
|
rimuoviTabellePerIniziare = true;
|
||||||
@@ -649,7 +669,9 @@ class Macro {
|
|||||||
{ new: true, upsert: false, returnOriginal: false }
|
{ new: true, upsert: false, returnOriginal: false }
|
||||||
).lean();
|
).lean();
|
||||||
|
|
||||||
product.productInfo = this.preparaProductInfo(product);
|
const productInfoOriginale = risprod?.productInfo || {};
|
||||||
|
const productInfoAggiornata = this.preparaProductInfo(product);
|
||||||
|
product.productInfo = { ...productInfoOriginale, ...productInfoAggiornata };
|
||||||
await this.gestisciCategorie(product);
|
await this.gestisciCategorie(product);
|
||||||
await this.gestisciAutori(product);
|
await this.gestisciAutori(product);
|
||||||
await this.gestisciEditore(product);
|
await this.gestisciEditore(product);
|
||||||
@@ -670,7 +692,6 @@ class Macro {
|
|||||||
await this.gestisciGasOrdine(product);
|
await this.gestisciGasOrdine(product);
|
||||||
await this.gestisciVariazioni(product, options);
|
await this.gestisciVariazioni(product, options);
|
||||||
|
|
||||||
|
|
||||||
const imagefile = await this.aggiornaImmagineSeNecessario(risprod, forzacaricamento || dataFutura);
|
const imagefile = await this.aggiornaImmagineSeNecessario(risprod, forzacaricamento || dataFutura);
|
||||||
if (imagefile) {
|
if (imagefile) {
|
||||||
product.productInfo.imagefile = imagefile;
|
product.productInfo.imagefile = imagefile;
|
||||||
@@ -1217,6 +1238,96 @@ class Macro {
|
|||||||
|
|
||||||
return mystr;
|
return mystr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async EsportaInfoProductExtra() {
|
||||||
|
console.log('EsportaInfoProductExtra...');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const products = await Product.find({}, campiProductInfo.map((f) => `productInfo.${f}`).join(' ')).lean();
|
||||||
|
|
||||||
|
const ws = fs.createWriteStream(CSV_PATH);
|
||||||
|
|
||||||
|
let prodExported = 0;
|
||||||
|
|
||||||
|
// Scrivi l'intestazione
|
||||||
|
const header = ['code', ...campiProductInfo.slice(1)]; // 'code' è il primo campo
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
const csvStream = csv.format({ headers: header });
|
||||||
|
csvStream.pipe(ws);
|
||||||
|
|
||||||
|
for (const p of products) {
|
||||||
|
const row = campiProductInfo.map((field) => p.productInfo?.[field] ?? '');
|
||||||
|
const rowToExport = campiProductInfo.slice(1).some((field) => p.productInfo && p.productInfo[field]);
|
||||||
|
if (rowToExport) {
|
||||||
|
csvStream.write(row);
|
||||||
|
prodExported++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
csvStream.end();
|
||||||
|
ws.on('finish', resolve);
|
||||||
|
ws.on('error', reject);
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`Esportazione completata: ${prodExported} su ${products.length} prodotti salvati in ${CSV_PATH}`);
|
||||||
|
return prodExported;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Errore durante l'esportazione:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async ImportaInfoProductExtra() {
|
||||||
|
console.log('ImportaInfoProductExtra...');
|
||||||
|
|
||||||
|
const records = [];
|
||||||
|
try {
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
const rs = fs.createReadStream(CSV_PATH);
|
||||||
|
rs.pipe(csv.parse({ headers: true }))
|
||||||
|
.on('error', reject)
|
||||||
|
.on('data', (row) => {
|
||||||
|
// Costruisci un oggetto productInfo corretto
|
||||||
|
const productInfo = {};
|
||||||
|
for (const field of campiProductInfo) {
|
||||||
|
productInfo[field] = row[field] ?? '';
|
||||||
|
}
|
||||||
|
records.push({
|
||||||
|
code: row.code, // usato per la ricerca
|
||||||
|
productInfo,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.on('end', resolve);
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`Letti ${records.length} record da ${CSV_PATH}`);
|
||||||
|
|
||||||
|
let aggiornati = 0;
|
||||||
|
for (const { code, productInfo } of records) {
|
||||||
|
if (!code) continue;
|
||||||
|
|
||||||
|
// Costruisci un oggetto $set con i campi annidati
|
||||||
|
const update = {};
|
||||||
|
for (const [key, value] of Object.entries(productInfo)) {
|
||||||
|
// Salta il campo 'code' perché è usato per la ricerca, non va aggiornato
|
||||||
|
if (key === 'code') continue;
|
||||||
|
update[`productInfo.${key}`] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await Product.findOneAndUpdate(
|
||||||
|
{ 'productInfo.code': code },
|
||||||
|
{ $set: update },
|
||||||
|
{ upsert: false, new: true }
|
||||||
|
).lean();
|
||||||
|
|
||||||
|
if (result) aggiornati++;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Aggiornati ${aggiornati} prodotti.`);
|
||||||
|
return aggiornati;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Errore durante l'importazione:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Macro;
|
module.exports = Macro;
|
||||||
|
|||||||
40771
src/server/products copia.csv
Normal file
40771
src/server/products copia.csv
Normal file
File diff suppressed because one or more lines are too long
39228
src/server/products.csv
Normal file
39228
src/server/products.csv
Normal file
File diff suppressed because one or more lines are too long
@@ -1858,8 +1858,13 @@ router.post('/duprec/:table/:id', authenticate, async (req, res) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/loadsite/:userId/:idapp', authenticate_noerror_WithUserLean, (req, res) => {
|
router.get('/loadsite/:userId/:idapp', authenticate_noerror_WithUserLean, async (req, res) => {
|
||||||
load(req, res, '0');
|
try {
|
||||||
|
await load(req, res, '0');
|
||||||
|
} catch (e) {
|
||||||
|
console.error('loadsite error', e);
|
||||||
|
res.status(500).send({ error: 'Impossibile caricare il sito' });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Funzione di test per misurare le performance di MongoDB
|
// Funzione di test per misurare le performance di MongoDB
|
||||||
@@ -2073,6 +2078,7 @@ async function load(req, res, version = '0') {
|
|||||||
crons: version >= 91 ? Cron.findAllIdApp() : Promise.resolve([]),
|
crons: version >= 91 ? Cron.findAllIdApp() : Promise.resolve([]),
|
||||||
raccoltacataloghis: version >= 91 ? RaccoltaCataloghi.findAllIdApp(idapp) : Promise.resolve([]),
|
raccoltacataloghis: version >= 91 ? RaccoltaCataloghi.findAllIdApp(idapp) : Promise.resolve([]),
|
||||||
myuserextra: req.user ? User.addExtraInfo(idapp, req.user, version) : Promise.resolve(null),
|
myuserextra: req.user ? User.addExtraInfo(idapp, req.user, version) : Promise.resolve(null),
|
||||||
|
statuscode2: version >= 91 ? req.statuscode2 : Promise.resolve([]),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Esecuzione parallela di tutte le promesse
|
// Esecuzione parallela di tutte le promesse
|
||||||
@@ -2187,6 +2193,7 @@ async function load(req, res, version = '0') {
|
|||||||
tipoformato: data.tipoformato,
|
tipoformato: data.tipoformato,
|
||||||
crons: data.crons,
|
crons: data.crons,
|
||||||
raccoltacataloghis: data.raccoltacataloghis,
|
raccoltacataloghis: data.raccoltacataloghis,
|
||||||
|
statuscode2: data.statuscode2,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2203,7 +2210,7 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate_noerror, async (req, res
|
|||||||
|
|
||||||
// console.log("POST " + process.env.LINK_CHECK_UPDATES + " userId=" + userId);
|
// console.log("POST " + process.env.LINK_CHECK_UPDATES + " userId=" + userId);
|
||||||
if (!req.user) {
|
if (!req.user) {
|
||||||
return res.status(200).send();
|
return res.status(req.code).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
await CfgServer.find({ idapp })
|
await CfgServer.find({ idapp })
|
||||||
|
|||||||
@@ -27,11 +27,9 @@ router.post('/', authenticate, async (req, res) => {
|
|||||||
} else {
|
} else {
|
||||||
return res.send({ code: server_constants.RIS_CODE_ERR, notif: '' });
|
return res.send({ code: server_constants.RIS_CODE_ERR, notif: '' });
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/setall/:username/:qualinotif/:idapp', authenticate, async (req, res) => {
|
router.get('/setall/:username/:qualinotif/:idapp', authenticate, async (req, res) => {
|
||||||
|
|
||||||
const idapp = req.params.idapp;
|
const idapp = req.params.idapp;
|
||||||
const username = req.params.username;
|
const username = req.params.username;
|
||||||
const qualinotif = parseInt(req.params.qualinotif);
|
const qualinotif = parseInt(req.params.qualinotif);
|
||||||
@@ -58,11 +56,9 @@ router.get('/setall/:username/:qualinotif/:idapp', authenticate, async (req, res
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.status(400).send(e);
|
res.status(400).send(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/set/:_id/:idapp', authenticate, async (req, res) => {
|
router.get('/set/:_id/:idapp', authenticate, async (req, res) => {
|
||||||
|
|
||||||
const _id = req.params._id;
|
const _id = req.params._id;
|
||||||
const username_call = req.user.username;
|
const username_call = req.user.username;
|
||||||
|
|
||||||
@@ -76,19 +72,14 @@ router.get('/set/:_id/:idapp', authenticate, async (req, res) => {
|
|||||||
return res.send(true);
|
return res.send(true);
|
||||||
}
|
}
|
||||||
res.send(false);
|
res.send(false);
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.status(400).send(e);
|
res.status(400).send(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
async function delNotif(res, idapp, username, id, username_call) {
|
async function delNotif(res, idapp, username, id, username_call) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (username === username_call) {
|
if (username === username_call) {
|
||||||
|
|
||||||
await SendNotif.findOneAndDelete({ idapp, _id: id });
|
await SendNotif.findOneAndDelete({ idapp, _id: id });
|
||||||
return res.send(true);
|
return res.send(true);
|
||||||
}
|
}
|
||||||
@@ -97,22 +88,17 @@ async function delNotif(res, idapp, username, id, username_call) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return res.send(false);
|
return res.send(false);
|
||||||
|
}
|
||||||
};
|
|
||||||
|
|
||||||
router.get('/del/:username/:id/:idapp', authenticate, async (req, res) => {
|
router.get('/del/:username/:id/:idapp', authenticate, async (req, res) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return delNotif(res, req.params.idapp, req.params.username, req.params.id, req.user.username);
|
return delNotif(res, req.params.idapp, req.params.username, req.params.id, req.user.username);
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return res.status(400).send(e);
|
return res.status(400).send(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
router.get('/delall/:username/:qualinotif/:idapp', authenticate, async (req, res) => {
|
router.get('/delall/:username/:qualinotif/:idapp', authenticate, async (req, res) => {
|
||||||
|
|
||||||
const idapp = req.params.idapp;
|
const idapp = req.params.idapp;
|
||||||
const username = req.params.username;
|
const username = req.params.username;
|
||||||
const qualinotif = parseInt(req.params.qualinotif);
|
const qualinotif = parseInt(req.params.qualinotif);
|
||||||
@@ -128,15 +114,13 @@ router.get('/delall/:username/:qualinotif/:idapp', authenticate, async (req, res
|
|||||||
query.typedir = { $ne: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS };
|
query.typedir = { $ne: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS };
|
||||||
}
|
}
|
||||||
const ris = await SendNotif.deleteMany(query);
|
const ris = await SendNotif.deleteMany(query);
|
||||||
if (ris)
|
if (ris) return res.send(true);
|
||||||
return res.send(true);
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return res.status(400).send(e);
|
return res.status(400).send(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.send(false);
|
return res.send(false);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/:username/:lastdataread/:idapp', authenticate_noerror, (req, res) => {
|
router.get('/:username/:lastdataread/:idapp', authenticate_noerror, (req, res) => {
|
||||||
@@ -144,7 +128,6 @@ router.get('/:username/:lastdataread/:idapp', authenticate_noerror, (req, res) =
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function getNotif(req, res) {
|
async function getNotif(req, res) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// tools.mylog('GET NotifS : ', req.params);
|
// tools.mylog('GET NotifS : ', req.params);
|
||||||
const username = req.params.username;
|
const username = req.params.username;
|
||||||
@@ -152,33 +135,54 @@ async function getNotif(req, res) {
|
|||||||
const idapp = req.params.idapp;
|
const idapp = req.params.idapp;
|
||||||
|
|
||||||
// var category = req.params.category;
|
// var category = req.params.category;
|
||||||
|
if (!req.user) {
|
||||||
|
return res.status(200).send();
|
||||||
|
}
|
||||||
|
|
||||||
if (req.user.idapp !== idapp) {
|
if (req.user.idapp !== idapp) {
|
||||||
// I'm trying to get something not mine!
|
// I'm trying to get something not mine!
|
||||||
return res.status(404).send({ code: server_constants.RIS_CODE_NOT_MY_USERNAME });
|
return res.status(404).send({ code: server_constants.RIS_CODE_NOT_MY_USERNAME });
|
||||||
}
|
}
|
||||||
|
|
||||||
const arrnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.QualiNotifs.OTHERS);
|
const arrnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(
|
||||||
|
username,
|
||||||
|
lastdataread,
|
||||||
|
idapp,
|
||||||
|
shared_consts.LIMIT_NOTIF_FOR_USER,
|
||||||
|
shared_consts.QualiNotifs.OTHERS
|
||||||
|
);
|
||||||
let arrnotifcoins_inattesa = null;
|
let arrnotifcoins_inattesa = null;
|
||||||
|
|
||||||
if (await User.isAdminByUsername(idapp, req.user.username)) {
|
if (await User.isAdminByUsername(idapp, req.user.username)) {
|
||||||
arrnotifcoins_inattesa = await SendNotif.findAllNotifCoinsAllIdAndIdApp(idapp);
|
arrnotifcoins_inattesa = await SendNotif.findAllNotifCoinsAllIdAndIdApp(idapp);
|
||||||
} else {
|
} else {
|
||||||
arrnotifcoins_inattesa = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIFCOINS_IN_ATTESA_FOR_USER, shared_consts.QualiNotifs.CIRCUITS, [{ status: 0 }]);
|
arrnotifcoins_inattesa = await SendNotif.findAllNotifByUsernameIdAndIdApp(
|
||||||
|
username,
|
||||||
|
lastdataread,
|
||||||
|
idapp,
|
||||||
|
shared_consts.LIMIT_NOTIFCOINS_IN_ATTESA_FOR_USER,
|
||||||
|
shared_consts.QualiNotifs.CIRCUITS,
|
||||||
|
[{ status: 0 }]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const arrnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIFCOINS_FOR_USER, shared_consts.QualiNotifs.CIRCUITS, [{ status: {$ne: 0 }}]);
|
const arrnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(
|
||||||
|
username,
|
||||||
|
lastdataread,
|
||||||
|
idapp,
|
||||||
|
shared_consts.LIMIT_NOTIFCOINS_FOR_USER,
|
||||||
|
shared_consts.QualiNotifs.CIRCUITS,
|
||||||
|
[{ status: { $ne: 0 } }]
|
||||||
|
);
|
||||||
|
|
||||||
//++Todo: Ottimizzare ! Non occorre inviare tutti questi dati !!! Solo per il Circuito ?!
|
//++Todo: Ottimizzare ! Non occorre inviare tutti questi dati !!! Solo per il Circuito ?!
|
||||||
const userprofile = await User.getExtraInfoByUsername(idapp, req.user.username);
|
const userprofile = await User.getExtraInfoByUsername(idapp, req.user.username);
|
||||||
|
|
||||||
return res.send({ arrnotif, arrnotifcoins: [...arrnotifcoins, ...arrnotifcoins_inattesa], userprofile });
|
return res.send({ arrnotif, arrnotifcoins: [...arrnotifcoins, ...arrnotifcoins_inattesa], userprofile });
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e.message);
|
console.log(e.message);
|
||||||
res.status(400).send(e);
|
res.status(400).send(e);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
@@ -94,13 +94,16 @@ router.delete('/del', authenticate, async (req, res) => {
|
|||||||
// tools.mylog("TOKENREM = " + req.token);
|
// tools.mylog("TOKENREM = " + req.token);
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const browser = req.get('User-Agent');
|
if (req.user) {
|
||||||
return await Subscription.findOneAndDelete(
|
const browser = req.get('User-Agent');
|
||||||
{ userId: req.user._id, access: req.access, browser }).then(() => {
|
return await Subscription.findOneAndDelete(
|
||||||
res.status(200).send();
|
{ userId: req.user._id, access: req.access, browser }).then(() => {
|
||||||
}, () => {
|
res.status(200).send();
|
||||||
res.status(400).send();
|
}, () => {
|
||||||
});
|
res.status(400).send();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
res.status(400).send();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Err:', e.message);
|
console.error('Err:', e.message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -659,8 +659,8 @@ router.post('/newtok', async (req, res) => {
|
|||||||
return res.status(400).send({ error: 'Refresh token mancante' });
|
return res.status(400).send({ error: 'Refresh token mancante' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const recFound = await User.findOne({ 'tokens.refreshToken': refreshToken });
|
const recFound = await User.findByRefreshTokenAnyAccess(refreshToken);
|
||||||
|
|
||||||
if (!recFound) {
|
if (!recFound) {
|
||||||
return res.status(403).send({ error: 'Refresh token non valido' });
|
return res.status(403).send({ error: 'Refresh token non valido' });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,24 +86,10 @@ module.exports = {
|
|||||||
paramemail.send = !previewonly;
|
paramemail.send = !previewonly;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (!transport) {
|
|
||||||
// transport = this.getTransport(mylocalsconf);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
if (transport) {
|
if (transport) {
|
||||||
paramemail.transport = transport;
|
paramemail.transport = transport;
|
||||||
} else {
|
} else {
|
||||||
paramemail.transport = this.getTransport(mylocalsconf);
|
paramemail.transport = this.getTransport(mylocalsconf);
|
||||||
/*
|
|
||||||
// console.log('1b . transport gmail');
|
|
||||||
paramemail.transport = {
|
|
||||||
service: 'gmail',
|
|
||||||
auth: {
|
|
||||||
user: tools.getEmailByIdApp(mylocalsconf.idapp),
|
|
||||||
pass: tools.getPwdByIdApp(mylocalsconf.idapp)
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// se non è presente la password, non inviare l'email e manda messaggio di errore !
|
// se non è presente la password, non inviare l'email e manda messaggio di errore !
|
||||||
|
|||||||
@@ -801,6 +801,7 @@ connectToDatabase(connectionUrl, options)
|
|||||||
'https://localhost:8085',
|
'https://localhost:8085',
|
||||||
'https://localhost:8088',
|
'https://localhost:8088',
|
||||||
'https://localhost:8099',
|
'https://localhost:8099',
|
||||||
|
'https://localhost:8094',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -970,7 +970,7 @@ const MyTelegramBot = {
|
|||||||
|
|
||||||
keyb = cl.getInlineKeyboard(myuser.lang, [
|
keyb = cl.getInlineKeyboard(myuser.lang, [
|
||||||
{
|
{
|
||||||
text: '✅ Abilita fiducia a ' + myuser.username,
|
text: '✅ Abilita fiducia a ' + myuser.username + ' in ' + name,
|
||||||
callback_data:
|
callback_data:
|
||||||
InlineConferma.RISPOSTA_SI +
|
InlineConferma.RISPOSTA_SI +
|
||||||
myfunc + tools.SEP +
|
myfunc + tools.SEP +
|
||||||
@@ -2506,7 +2506,7 @@ class Telegram {
|
|||||||
file = '~/batch/test_restart_server.sh';
|
file = '~/batch/test_restart_server.sh';
|
||||||
}
|
}
|
||||||
|
|
||||||
let messaggio = this.chisono(rec) + ' Restart il Server (Node.Js) : ' + process.version;
|
let messaggio = this.chisono(rec) + ' Restart il Server (Node.Js) : ' + file + ' ' + process.version;
|
||||||
|
|
||||||
messaggio += '\nVersione Server: ' + (await tools.getVersServer());
|
messaggio += '\nVersione Server: ' + (await tools.getVersServer());
|
||||||
|
|
||||||
|
|||||||
@@ -1247,8 +1247,8 @@ module.exports = {
|
|||||||
cmdrichiesta,
|
cmdrichiesta,
|
||||||
myuserdata,
|
myuserdata,
|
||||||
usernameDest,
|
usernameDest,
|
||||||
'',
|
|
||||||
circuitname,
|
circuitname,
|
||||||
|
'',
|
||||||
myreccircuit._id,
|
myreccircuit._id,
|
||||||
'',
|
'',
|
||||||
extrarec.groupname
|
extrarec.groupname
|
||||||
@@ -6082,25 +6082,30 @@ module.exports = {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
aggiornatoimg = { ris: false };
|
aggiornatoimg = { ris: false };
|
||||||
}
|
}
|
||||||
|
let nontrovato = false;
|
||||||
if (
|
if (
|
||||||
aggiornatoimg?.code === 404 ||
|
aggiornatoimg?.code === 404 ||
|
||||||
(aggiornatoimg?.filepath && aggiornatoimg?.filepath?.includes('noimg.jpg'))
|
(aggiornatoimg?.filepath && aggiornatoimg?.filepath?.includes('noimg.jpg'))
|
||||||
) {
|
) {
|
||||||
|
nontrovato = true;
|
||||||
// non trovato quindi la prossima volta non richiederlo
|
// non trovato quindi la prossima volta non richiederlo
|
||||||
await Product.setImgNotFound(product._id);
|
await Product.setImgNotFound(product._id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aggiornatoimg?.filepath?.includes('noimg.jpg')) {
|
if (aggiornatoimg?.filepath?.includes('noimg.jpg')) {
|
||||||
// nascondi il prodotto se non trovo l'immagine !
|
// nascondi il prodotto se non trovo l'immagine !
|
||||||
await Product.updateOne({ _id: product._id }, { $set: { deleted: true } });
|
// await Product.updateOne({ _id: product._id }, { $set: { deleted: true } });
|
||||||
|
|
||||||
aggiornatoimg = { ris: false, deleted: true };
|
aggiornatoimg = { ris: false, deleted: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aggiornatoimg?.filepath) {
|
if (aggiornatoimg?.filepath) {
|
||||||
const filenamebase = path.basename(aggiornatoimg.filepath);
|
const filenamebase = path.basename(aggiornatoimg.filepath);
|
||||||
// const img = '/upload/products/' + filenamebase;
|
// const img = '/upload/products/' + filenamebase;
|
||||||
imagefile = filenamebase;
|
imagefile = filenamebase;
|
||||||
|
if (nontrovato) {
|
||||||
|
imagefile = '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { imagefile, aggiornatoimg: aggiornatoimg.ris };
|
return { imagefile, aggiornatoimg: aggiornatoimg.ris };
|
||||||
@@ -6236,6 +6241,17 @@ module.exports = {
|
|||||||
return mydate;
|
return mydate;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
areDifferentArrayString(array1, array2) {
|
||||||
|
// confronta l'array1 con l'array2 (sono array di stringhe) e torna se sono diversi
|
||||||
|
return !array1.every((val, index) => array2[index] === val);
|
||||||
|
},
|
||||||
|
|
||||||
|
areDifferentProduct(array1prod, array2prod) {
|
||||||
|
// confronta l'array1 con l'array2 e torna se sono diversi
|
||||||
|
// la struttura è product.productInfo.code , quindi puoi controllare se sono uguali il code
|
||||||
|
return !array1prod.every((val1, index) => array2prod[index].productInfo.code === val1.productInfo.code);
|
||||||
|
},
|
||||||
|
|
||||||
getvalueByJsonText(valore) {
|
getvalueByJsonText(valore) {
|
||||||
if (valore && valore['#text']) {
|
if (valore && valore['#text']) {
|
||||||
if (valore['#text']) return valore['#text'];
|
if (valore['#text']) return valore['#text'];
|
||||||
|
|||||||
@@ -973,6 +973,7 @@ module.exports = {
|
|||||||
max_partecip: 1,
|
max_partecip: 1,
|
||||||
contribstr: 1,
|
contribstr: 1,
|
||||||
link_maplocation: 1,
|
link_maplocation: 1,
|
||||||
|
link_conference: 1,
|
||||||
//**ADDFIELD_MYBACHECAS
|
//**ADDFIELD_MYBACHECAS
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
1.2.71
|
1.2.72
|
||||||
0
upload/products.csv
Normal file
0
upload/products.csv
Normal file
|
|
Reference in New Issue
Block a user