fix: Upload Foto

This commit is contained in:
paoloar77
2022-02-16 09:40:16 +01:00
parent a3502c1d9d
commit bae30504f7
9 changed files with 147 additions and 63 deletions

View File

@@ -128,6 +128,7 @@ MySkillSchema.statics.getFieldsLastForSearch = function() {
]; ];
}; };
MySkillSchema.statics.executeQueryTable = function(idapp, params) { MySkillSchema.statics.executeQueryTable = function(idapp, params) {
params.fieldsearch = this.getFieldsForSearch(); params.fieldsearch = this.getFieldsForSearch();
params.fieldsearch_last = this.getFieldsLastForSearch(); params.fieldsearch_last = this.getFieldsLastForSearch();
@@ -147,6 +148,7 @@ MySkillSchema.statics.executeQueryTable = function(idapp, params) {
idContribType: 1, idContribType: 1,
idCity: 1, idCity: 1,
numLevel: 1, numLevel: 1,
adType: 1,
photos: 1, photos: 1,
note: 1, note: 1,
descr: 1, descr: 1,
@@ -231,6 +233,7 @@ MySkillSchema.statics.getMySkillByIdkill = function(idapp, idSkill) {
'idContribType': 1, 'idContribType': 1,
'idCity': 1, 'idCity': 1,
'numLevel': 1, 'numLevel': 1,
adType: 1,
'photos': 1, 'photos': 1,
'note': 1, 'note': 1,
'descr': 1, 'descr': 1,
@@ -280,6 +283,7 @@ MySkillSchema.statics.getMySkillByIdkill = function(idapp, idSkill) {
'idContribType': 1, 'idContribType': 1,
'idCity': 1, 'idCity': 1,
'numLevel': 1, 'numLevel': 1,
adType: 1,
'photos': 1, 'photos': 1,
'note': 1, 'note': 1,
'descr': 1, 'descr': 1,
@@ -329,6 +333,7 @@ MySkillSchema.statics.getMySkillByIdkill = function(idapp, idSkill) {
'idContribType': 1, 'idContribType': 1,
'idCity': 1, 'idCity': 1,
'numLevel': 1, 'numLevel': 1,
adType: 1,
'photos': 1, 'photos': 1,
'note': 1, 'note': 1,
'descr': 1, 'descr': 1,
@@ -378,6 +383,7 @@ MySkillSchema.statics.getMySkillByIdkill = function(idapp, idSkill) {
'idContribType': 1, 'idContribType': 1,
'idCity': 1, 'idCity': 1,
'numLevel': 1, 'numLevel': 1,
adType: 1,
'photos': 1, 'photos': 1,
'note': 1, 'note': 1,
'descr': 1, 'descr': 1,
@@ -427,6 +433,7 @@ MySkillSchema.statics.getMySkillByIdkill = function(idapp, idSkill) {
'idContribType': 1, 'idContribType': 1,
'idCity': 1, 'idCity': 1,
'numLevel': 1, 'numLevel': 1,
adType: 1,
'photos': 1, 'photos': 1,
'note': 1, 'note': 1,
'descr': 1, 'descr': 1,
@@ -449,6 +456,14 @@ MySkillSchema.statics.getMySkillByIdkill = function(idapp, idSkill) {
}); });
}; };
MySkillSchema.statics.getCompleteRecord = function(idapp, id) {
const MySkill = this;
return MySkill.getMySkillByIdkill(idapp, id);
};
const MySkill = mongoose.model('MySkill', MySkillSchema); const MySkill = mongoose.model('MySkill', MySkillSchema);
module.exports = {MySkill}; module.exports = {MySkill};

View File

@@ -137,18 +137,16 @@ module.exports = {
"label" : "Dono", "label" : "Dono",
"__v" : 0 "__v" : 0
}, },
{ {
"_id" : ObjectID("51bc466567de9a1f54b254f4"), "_id" : ObjectID("51bc466567de9a1f54b254f4"),
"idapp" : "13", "idapp" : "13",
"label" : "Offerta Libera", "label" : "Offerta Libera",
"__v" : 0 "__v" : 0
}, },
{ {
"_id" : ObjectID("51bc454867de9a1f54b254f2"), "_id" : ObjectID("51bc454867de9a1f54b254f2"),
"idapp" : "13", "idapp" : "13",
"label" : "Baratto (scambio Beni o Servizi)", "label" : "Baratto",
"__v" : 0 "__v" : 0
}, },
{ {
@@ -163,11 +161,41 @@ module.exports = {
"label" : "Monete Alternative", "label" : "Monete Alternative",
"__v" : 0 "__v" : 0
}, },
{
"_id" : ObjectID("51bc482667de9a1f64b254ac"),
"idapp" : "13",
"label" : "Ris (RISO)",
"__v" : 0
},
{
"_id" : ObjectID("51bc482667de9a1f64b254ad"),
"idapp" : "13",
"label" : "Sardex",
"__v" : 0
},
{
"_id" : ObjectID("51bc482667de9a1f64b254ae"),
"idapp" : "13",
"label" : "Gaiax (ProItaly)",
"__v" : 0
},
{
"_id" : ObjectID("51bc482667de9a1f64b254af"),
"idapp" : "13",
"label" : "Val (VAL.AZ.CO.)",
"__v" : 0
},
{ {
"_id" : ObjectID("51bc482667de9a1f64b254fb"), "_id" : ObjectID("51bc482667de9a1f64b254fb"),
"idapp" : "13", "idapp" : "13",
"label" : "Euro", "label" : "Euro",
"__v" : 0 "__v" : 0
}, },
{
"_id" : ObjectID("51bc482667de9a1f64b257fb"),
"idapp" : "13",
"label" : "Criptomonete",
"__v" : 0
},
] ]
} }

View File

@@ -1,10 +1,8 @@
module.exports = { module.exports = {
list: [ list: [
{_id: 0, descr: '[Nessuno]', years_of_exp: 0}, {_id: 0, descr: '[Nessuno]', years_of_exp: 0},
{_id: 1, descr: 'Principiante', years_of_exp: 1}, {_id: 1, descr: 'Elementare', years_of_exp: 1},
{_id: 2, descr: 'Intermedio', years_of_exp: 3}, {_id: 2, descr: 'Intermedio', years_of_exp: 3},
{_id: 3, descr: 'Avanzato', years_of_exp: 5}, {_id: 3, descr: 'Avanzato', years_of_exp: 5},
{_id: 4, descr: 'Esperto', years_of_exp: 10},
{_id: 5, descr: 'Veterano', years_of_exp: 20},
], ],
}; };

View File

@@ -169,6 +169,7 @@ module.exports = {
const {Contribtype} = require('../models/contribtype'); const {Contribtype} = require('../models/contribtype');
await this.insertIntoDb_NoDuplicate(false, 'contribtypes', Contribtype, 'label') await this.insertIntoDb_NoDuplicate(false, 'contribtypes', Contribtype, 'label')
// AdTypes
const {AdType} = require('../models/adtype'); const {AdType} = require('../models/adtype');
await this.insertIntoDb_NoDuplicate(abilita, 'adtypes', AdType, 'descr') await this.insertIntoDb_NoDuplicate(abilita, 'adtypes', AdType, 'descr')

View File

@@ -370,7 +370,9 @@ router.post('/settable', authenticate, (req, res) => {
if (params.table === shared_consts.TAB_MYGROUPS) { if (params.table === shared_consts.TAB_MYGROUPS) {
if (shared_consts.MYGROUPS_KEY_TO_CRYPTED in mydata) { if (shared_consts.MYGROUPS_KEY_TO_CRYPTED in mydata) {
if (mydata[shared_consts.MYGROUPS_KEY_TO_CRYPTED]) { if (mydata[shared_consts.MYGROUPS_KEY_TO_CRYPTED]) {
mydata[shared_consts.MYGROUPS_KEY_TO_CRYPTED + shared_consts.SUFFIX_CRYPTED] = tools.cryptdata(mydata[shared_consts.MYGROUPS_KEY_TO_CRYPTED]); mydata[shared_consts.MYGROUPS_KEY_TO_CRYPTED +
shared_consts.SUFFIX_CRYPTED] = tools.cryptdata(
mydata[shared_consts.MYGROUPS_KEY_TO_CRYPTED]);
} }
} }
@@ -388,7 +390,8 @@ router.post('/settable', authenticate, (req, res) => {
*/ */
} }
const indfind = mydata.admins.findIndex((rec) => (rec.username === req.user.username)); const indfind = mydata.admins.findIndex(
(rec) => (rec.username === req.user.username));
if (indfind < 0) { if (indfind < 0) {
mydata.admins.push({username: req.user.username}); mydata.admins.push({username: req.user.username});
@@ -416,30 +419,39 @@ router.post('/settable', authenticate, (req, res) => {
} }
} }
return mytablerec.save().then(rec => { return mytablerec.save().
// tools.mylog('rec', rec); then(async (rec) => {
return res.send(rec);
}).catch((e) => { if (shared_consts.TABLES_GETCOMPLETEREC.includes(params.table)) {
if (e.code === 11000) { const myrec = await mytablestrutt.getCompleteRecord(rec.idapp,
const id = mytablerec._id; rec._id);
delete mytablerec._doc['_id']; return res.send(myrec);
const myfields = mytablerec._doc; } else {
if (!myfields.userId) { return res.send(rec);
myfields.userId = req.user._id.toString(); }
}
return mytablestrutt.findByIdAndUpdate(id, {$set: myfields}). // tools.mylog('rec', rec);
then(async (rec) => {
return res.send(rec); }).catch((e) => {
}). if (e.code === 11000) {
catch((err) => { const id = mytablerec._id;
tools.mylog('error: ', err.message); delete mytablerec._doc['_id'];
return res.status(400).send(err); const myfields = mytablerec._doc;
}); if (!myfields.userId) {
} else { myfields.userId = req.user._id.toString();
console.log(e.message); }
} return mytablestrutt.findByIdAndUpdate(id, {$set: myfields}).
}); then(async (rec) => {
return res.send(rec);
}).
catch((err) => {
tools.mylog('error: ', err.message);
return res.status(400).send(err);
});
} else {
console.log(e.message);
}
});
} catch (e) { } catch (e) {
return res.status(400).send(e); return res.status(400).send(e);
@@ -716,7 +728,9 @@ router.patch('/chval', authenticate, async (req, res) => {
msg = 'Ripristinato'; msg = 'Ripristinato';
await telegrambot.sendMsgTelegramToTheManagers(idapp, await telegrambot.sendMsgTelegramToTheManagers(idapp,
`L\'utente ` + tools.getNomeCognomeEUserNameByUser(rec) + ` è stato ${msg} da ` + tools.getNomeCognomeEUserNameByUser(req.user)); `L\'utente ` + tools.getNomeCognomeEUserNameByUser(rec) +
` è stato ${msg} da ` +
tools.getNomeCognomeEUserNameByUser(req.user));
} }
} }
@@ -728,8 +742,10 @@ router.patch('/chval', authenticate, async (req, res) => {
fieldsvalue.aportador_solidario); fieldsvalue.aportador_solidario);
const nomecognomeas = await User.getNameSurnameByUsername(idapp, const nomecognomeas = await User.getNameSurnameByUsername(idapp,
rec.aportador_solidario); rec.aportador_solidario);
msg = `Variato l'invitante di ` + tools.getNomeCognomeEUserNameByUser(rec) + msg = `Variato l'invitante di ` +
'\nmodificato da ' + tools.getNomeCognomeEUserNameByUser(req.user) + tools.getNomeCognomeEUserNameByUser(rec) +
'\nmodificato da ' +
tools.getNomeCognomeEUserNameByUser(req.user) +
' \n' + ' \n' +
'Prima: ' + nomecognomeas + ' (' + rec.aportador_solidario + 'Prima: ' + nomecognomeas + ' (' + rec.aportador_solidario +
')\n' + ')\n' +
@@ -1167,7 +1183,7 @@ function load(req, res, version) {
myuserextra, myuserextra,
catgrps, catgrps,
adtypes, adtypes,
]).then((arrdata) => { ]).then((arrdata) => {
// console.table(arrdata); // console.table(arrdata);
let myuser = req.user; let myuser = req.user;
if (myuser) { if (myuser) {
@@ -1418,10 +1434,12 @@ function uploadFile(req, res, version) {
// res.sendFile(path.resolve(filename)); // res.sendFile(path.resolve(filename));
oldpath = file.path; oldpath = file.path;
// newname = '/home/paolo/Documents/prova.png'
file.path = newname; file.path = newname;
// Move in the folder application ! // Move in the folder application !
tools.move(oldpath, newname, (err) => { // tools.move(oldpath, newname, (err) => {
tools.move(oldpath, newname, async (err) => {
if (err) if (err)
console.log('err:', err); console.log('err:', err);
@@ -1444,26 +1462,27 @@ function uploadFile(req, res, version) {
}; };
// Salva le immagini in formato compresso // Salva le immagini in formato compresso
(async () => { try {
try { const ris = await resizer(newname, setup_image_compress);
const ris = await resizer(newname, setup_image_compress); console.log('resizer', newname);
if (ris) {
if (tools.isFileExists(resized_img)) {
tools.delete(newname, false, () => {});
if (ris) { tools.move(resized_img, newname, (err) => {
if (tools.isFileExists(resized_img)) { if (err)
tools.delete(newname, false, () => {}); console.error('err', err);
else
tools.move(resized_img, newname, (err) => { console.log('move', newname);
if (err) });
console.error('err', err);
});
}
} }
} catch (e) {
console.error('newname', e);
} }
} catch (e) {
console.error('newname', e);
}
})();
res.end(); res.end();
console.log('res.end');
// return res.send({filename: newname }); // return res.send({filename: newname });
}); });

View File

@@ -361,7 +361,7 @@ router.post('/login', (req, res) => {
var user = new User(body); var user = new User(body);
// const subs = _.pick(req.body, ['subs']); // const subs = _.pick(req.body, ['subs']);
// tools.mylog("LOGIN: username: " + user.username + " pwd = " + user.password); // tools.mylog("LOG: u: " + user.username + " p:" + user.password);
// tools.mylog("user REC:", user); // tools.mylog("user REC:", user);
@@ -381,18 +381,11 @@ router.post('/login', (req, res) => {
tools.mylogshow(msg); tools.mylogshow(msg);
// telegrambot.sendMsgTelegramToTheManagers(body.idapp, msg); // telegrambot.sendMsgTelegramToTheManagers(body.idapp, msg);
res.status(404).send({code: server_constants.RIS_CODE_LOGIN_ERR}); res.status(404).send({code: server_constants.RIS_CODE_LOGIN_ERR});
} else if (!!user.subaccount && user.subaccount) {
await tools.snooze(1000);
// const msg = "Tentativo di Login ERRATO [" + body.username + ' , ' + body.password + ']\n' + '[IP: ' + tools.getiPAddressUser(req) + ']';
// tools.mylogshow(msg);
// telegrambot.sendMsgTelegramToTheManagers(body.idapp, msg);
res.status(404).
send({code: server_constants.RIS_CODE_LOGIN_ERR_SUBACCOUNT});
return null;
} }
return user; return user;
}). }).
then(user => { then(user => {
// console.log('Lgn-Ok');
if (user) { if (user) {
return user.generateAuthToken(req).then((token) => { return user.generateAuthToken(req).then((token) => {
var usertosend = new User(); var usertosend = new User();
@@ -421,6 +414,7 @@ router.post('/login', (req, res) => {
return (subscribe !== null); return (subscribe !== null);
}). }).
then(subsExistonDb => { then(subsExistonDb => {
// console.log('ESEGUITO OK')
return { return {
usertosend: myris.usertosend, usertosend: myris.usertosend,
token: myris.token, token: myris.token,
@@ -451,7 +445,7 @@ router.post('/login', (req, res) => {
} }
}). }).
catch((e) => { catch((e) => {
tools.mylog('ERRORE IN LOGIN: ' + e.message); console.error('ERRORE IN LOGIN: ' + e.message);
if (!resalreadysent) if (!resalreadysent)
res.status(400). res.status(400).
send({code: server_constants.RIS_CODE_LOGIN_ERR_GENERIC}); send({code: server_constants.RIS_CODE_LOGIN_ERR_GENERIC});
@@ -918,18 +912,34 @@ async function eseguiDbOp(idapp, mydata, locale) {
} else if (mydata.dbop === 'emptyDbSkill') { } else if (mydata.dbop === 'emptyDbSkill') {
// Svuota e Ricrea
const {Sector} = require('../models/sector'); const {Sector} = require('../models/sector');
const {Skill} = require('../models/skill'); const {Skill} = require('../models/skill');
const {SubSkill} = require('../models/subskill'); const {SubSkill} = require('../models/subskill');
const {City} = require('../models/city'); const {Contribtype} = require('../models/contribtype');
const {Province} = require('../models/province'); const {AdType} = require('../models/adtype');
await Sector.deleteMany({}); await Sector.deleteMany({});
await Skill.deleteMany({}); await Skill.deleteMany({});
await SubSkill.deleteMany({}); await SubSkill.deleteMany({});
await Contribtype.deleteMany({});
await AdType.deleteMany({});
await populate.popolaTabelleNuove();
} else if (mydata.dbop === 'ricreaTabCitiesProvinces') {
// Svuota e Ricrea
const {City} = require('../models/city');
const {Province} = require('../models/province');
await City.deleteMany({}); await City.deleteMany({});
await Province.deleteMany({}); await Province.deleteMany({});
await populate.popolaTabelleNuove();
} else if (mydata.dbop === 'PopulateTables') { } else if (mydata.dbop === 'PopulateTables') {
populate.popolaTabelleNuove(); populate.popolaTabelleNuove();

View File

@@ -140,6 +140,7 @@ MsgBot = {
'mi sposi'], 'mi sposi'],
CHE_TEMPO_FA: ['che tempo'], CHE_TEMPO_FA: ['che tempo'],
NON_TROO_INVITATI: ['non trovo invitati', 'non riesco a trovare invitati'], NON_TROO_INVITATI: ['non trovo invitati', 'non riesco a trovare invitati'],
TROVAMI_UN_UOMO_DONNA: ['trovami un uomo', 'trovami una donna', 'esiste una donna per me', 'esiste un uomo per me'],
PAROLACCE: [ PAROLACCE: [
'stronz', 'stronz',
'fanculo', 'fanculo',
@@ -1566,6 +1567,8 @@ class Telegram {
emo.GIFT_HEART; emo.GIFT_HEART;
} else if (MsgBot.MA_ALLORA.find((rec) => testo.indexOf(rec) > -1)) { } else if (MsgBot.MA_ALLORA.find((rec) => testo.indexOf(rec) > -1)) {
risp = 'Ma allora cosa?'; risp = 'Ma allora cosa?';
} else if (MsgBot.TROVAMI_UN_UOMO_DONNA.find((rec) => testo.indexOf(rec) > -1)) {
risp = 'Eh non è cosi facile. Ma se t\'impegni a cercare ci riuscirai. Nel frattempo trova la tua strada, fai il tuo percorso interiore, e magari arriva proprio quando meno te l\'aspetti';
} else if (MsgBot.SEI_LIBERO_STASERA.find( } else if (MsgBot.SEI_LIBERO_STASERA.find(
(rec) => testo.indexOf(rec) > -1)) { (rec) => testo.indexOf(rec) > -1)) {
risp = 'Si vabbeh, non è che puoi prendere subito tutta questa confidenza' + risp = 'Si vabbeh, non è che puoi prendere subito tutta questa confidenza' +

View File

@@ -2139,6 +2139,14 @@ module.exports = {
} }
}, },
copy(oldPath, newPath, callback) {
fs.copyFile(oldPath, newPath, (err) => {
if (err) throw err;
// console.log('source.txt was copied to destination.txt');
});
},
extractFileName: function(filename) { extractFileName: function(filename) {
return path.basename(filename); return path.basename(filename);
}, },
@@ -2155,6 +2163,7 @@ module.exports = {
let img_small = path.dirname(mypath) + '/' + let img_small = path.dirname(mypath) + '/' +
server_constants.PREFIX_IMG_SMALL + path.basename(mypath); server_constants.PREFIX_IMG_SMALL + path.basename(mypath);
fs.unlink(img_small, () => {}); fs.unlink(img_small, () => {});
console.log('delete file', mypath)
} catch (e) { } catch (e) {
console.error(err); console.error(err);
} }

View File

@@ -89,6 +89,7 @@ module.exports = {
TABLES_USER_ID: ['myskills', 'mygroups'], TABLES_USER_ID: ['myskills', 'mygroups'],
TABLES_USER_INCLUDE_MY: ['mygroups'], TABLES_USER_INCLUDE_MY: ['mygroups'],
TABLES_UPDATE_LASTMODIFIED: ['myskills', 'mybots', 'mygroups'], TABLES_UPDATE_LASTMODIFIED: ['myskills', 'mybots', 'mygroups'],
TABLES_GETCOMPLETEREC: ['myskills'],
TABLES_PERM_CHANGE_FOR_USERS: ['myskills', 'mygroups'], TABLES_PERM_CHANGE_FOR_USERS: ['myskills', 'mygroups'],
TABLES_PERM_NEWREC: ['skills', 'subskills', 'mygroups'], TABLES_PERM_NEWREC: ['skills', 'subskills', 'mygroups'],