nuova veste grafica: myskills, mygoods, mybachecas, myhosps,
- cambiato id (da numero a stringa)
This commit is contained in:
@@ -1246,6 +1246,48 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
||||
await City.remove({});
|
||||
await Province.remove({});
|
||||
|
||||
} else if (mydata.dbop === 'ConvTablesFromIntToString') {
|
||||
|
||||
const { MySkill } = require('../models/myskill');
|
||||
const { MyBacheca } = require('../models/mybacheca');
|
||||
const { MyHosp } = require('../models/myhosp');
|
||||
const { MyGood } = require('../models/mygood');
|
||||
const { MyGroup } = require('../models/mygroup');
|
||||
|
||||
console.log('INIZIO - Conversioni');
|
||||
// 'myskills',
|
||||
// 'mybachecas',
|
||||
// 'myhosps',
|
||||
// 'mygoods',
|
||||
// 'mygroups'
|
||||
|
||||
await ConvertiDaIntAStr(MySkill);
|
||||
await ConvertiDaIntAStr(MyBacheca);
|
||||
await ConvertiDaIntAStr(MyHosp);
|
||||
await ConvertiDaIntAStr(MyGood);
|
||||
await ConvertiDaIntAStr(MyGroup);
|
||||
|
||||
console.log('FINE - Conversioni');
|
||||
|
||||
} else if (mydata.dbop === 'Removeinteger') {
|
||||
|
||||
const { MySkill } = require('../models/myskill');
|
||||
const { MyBacheca } = require('../models/mybacheca');
|
||||
const { MyHosp } = require('../models/myhosp');
|
||||
const { MyGood } = require('../models/mygood');
|
||||
const { MyGroup } = require('../models/mygroup');
|
||||
|
||||
console.log('INIZIO - Rimozione');
|
||||
|
||||
await RimuoviInteri(MySkill);
|
||||
await RimuoviInteri(MyBacheca);
|
||||
await RimuoviInteri(MyHosp);
|
||||
await RimuoviInteri(MyGood);
|
||||
await RimuoviInteri(MyGroup);
|
||||
|
||||
console.log('FINE - Rimozione');
|
||||
|
||||
|
||||
} else if (mydata.dbop === 'createAllCircuits') {
|
||||
const { Province } = require('../models/province');
|
||||
|
||||
@@ -1318,6 +1360,77 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
||||
}
|
||||
};
|
||||
|
||||
async function ConvertiDaIntAStr(mytable) {
|
||||
try {
|
||||
console.log('INIZIO - ConvertiDaIntAStr ', mytable.modelName);
|
||||
|
||||
return await mytable.find({ '_id': { $type: 16 } })
|
||||
.then(async (arr) => {
|
||||
console.log('num record ', arr.length)
|
||||
|
||||
let ind = 0;
|
||||
for (let x of arr) {
|
||||
|
||||
const idnew = x._id;
|
||||
|
||||
if (idnew < 10000) {
|
||||
|
||||
const idint = parseInt(x._id, 10) + 10000;
|
||||
|
||||
const myrec = new mytable(x._doc);
|
||||
|
||||
myrec._doc.date_created = x._doc.date_created;
|
||||
myrec._doc.date_updated = x._doc.date_updated;
|
||||
|
||||
if (!myrec._doc.date_updated) {
|
||||
if (myrec.hasOwnProperty('date_created'))
|
||||
myrec._doc.date_updated = myrec._doc.date_created;
|
||||
}
|
||||
if ((myrec.hasOwnProperty('date_updated') && !myrec._doc.date_created))
|
||||
myrec._doc.date_created = myrec._doc.date_updated;
|
||||
myrec._doc._id = idint + '';
|
||||
|
||||
let ris = await myrec.save((async function (err, doc) {
|
||||
if (doc) {
|
||||
ind++;
|
||||
//await mytable.findOneAndRemove({ _id: parseInt(doc._id, 10) });
|
||||
console.log('++Add (', ind, ')', doc._id);
|
||||
} else {
|
||||
const myid = parseInt(err.keyValue._id, 10) + 0;
|
||||
const canc = await mytable.findOneAndRemove({ _id: myid });
|
||||
if (canc)
|
||||
console.log('err', err.message, 'canc', canc._doc._id);
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
console.log('FINE - ConvertiDaIntAStr ', mytable.modelName);
|
||||
});
|
||||
|
||||
|
||||
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
async function RimuoviInteri(mytable) {
|
||||
try {
|
||||
console.log('INIZIO - RimuoviInteri ', mytable.modelName);
|
||||
|
||||
const arr = await mytable.find({ '_id': { $lte: 10000 } })
|
||||
console.log(' search interi...', arr.length);
|
||||
|
||||
const ris = await mytable.deleteMany({ '_id': { $lte: 10000 } })
|
||||
|
||||
console.log('FINE - RimuoviInteri ', mytable.modelName, ris);
|
||||
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
async function eseguiDbOpUser(idapp, mydata, locale, req, res) {
|
||||
|
||||
let ris = await User.DbOp(idapp, mydata);
|
||||
@@ -1451,15 +1564,19 @@ router.post('/cmd', authenticate, async (req, res) => {
|
||||
let ris = null;
|
||||
|
||||
if (cmd === shared_consts.CMD_USER.SET_FAVORITE) {
|
||||
if (value)
|
||||
ris = await User.addFavorite(idapp, username, id, tab);
|
||||
else
|
||||
ris = await User.removeFavorite(idapp, username, id, tab);
|
||||
if (tab) {
|
||||
if (value)
|
||||
ris = await User.addFavorite(idapp, username, id, tab);
|
||||
else
|
||||
ris = await User.removeFavorite(idapp, username, id, tab);
|
||||
}
|
||||
} else if (cmd === shared_consts.CMD_USER.SET_BOOKMARK) {
|
||||
if (value)
|
||||
ris = await User.addBookmark(idapp, username, id, tab);
|
||||
else
|
||||
ris = await User.removeBookmark(idapp, username, id, tab);
|
||||
if (tab) {
|
||||
if (value)
|
||||
ris = await User.addBookmark(idapp, username, id, tab);
|
||||
else
|
||||
ris = await User.removeBookmark(idapp, username, id, tab);
|
||||
}
|
||||
}
|
||||
|
||||
let state = (value && ris && ris.ok === 1) ? 1 : ((!value && ris && ris.ok === 1) ? -1 : 0);
|
||||
|
||||
Reference in New Issue
Block a user