aggiornato prodotti e scontistica
This commit is contained in:
@@ -22,6 +22,12 @@ const CatProdSchema = new Schema({
|
||||
img: {
|
||||
type: String,
|
||||
},
|
||||
icon: {
|
||||
type: String,
|
||||
},
|
||||
color: {
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
|
||||
CatProdSchema.statics.getAllCategories = function (callback) {
|
||||
|
||||
@@ -66,6 +66,11 @@ const productSchema = new Schema({
|
||||
default: 1,
|
||||
required: true,
|
||||
},
|
||||
minStepQty: { // step quantità acquistabile
|
||||
type: Number,
|
||||
default: 1,
|
||||
required: true,
|
||||
},
|
||||
maxBookableQty: { // quantità massima Pre-ordinabile (singolarmente)
|
||||
type: Number,
|
||||
default: 0,
|
||||
@@ -113,6 +118,12 @@ const productSchema = new Schema({
|
||||
cat_name: {
|
||||
type: String,
|
||||
},
|
||||
sconto1: {
|
||||
type: String,
|
||||
},
|
||||
sconto2: {
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
|
||||
var Product = module.exports = mongoose.model('Product', productSchema);
|
||||
@@ -502,6 +513,7 @@ module.exports.singlerecconvert_AfterImport = async function (idapp, prod, isnuo
|
||||
objtoset = {
|
||||
idapp,
|
||||
minBuyQty: 1,
|
||||
minStepQty: 1,
|
||||
maxBookableQty: 0,
|
||||
}
|
||||
}
|
||||
@@ -563,6 +575,46 @@ module.exports.singlerecconvert_AfterImport = async function (idapp, prod, isnuo
|
||||
}
|
||||
}
|
||||
|
||||
let arrsconti = []
|
||||
|
||||
if (prod.sconto1) {
|
||||
// Cerca la scontistica
|
||||
let recscontistica = await Scontistica.findOne({ idapp, code: prod.sconto1 }).lean();
|
||||
if (!recscontistica) {
|
||||
recscontistica = new Scontistica({ idapp, code: prod.sconto1 });
|
||||
// Non esiste questa scontistica, quindi lo creo !
|
||||
ris = await recscontistica.save();
|
||||
recscontistica = await Scontistica.findOne({ idapp, code: prod.sconto1 }).lean();
|
||||
}
|
||||
|
||||
if (recscontistica) {
|
||||
arrsconti.push(recscontistica);
|
||||
}
|
||||
}
|
||||
|
||||
if (prod.sconto2) {
|
||||
// Cerca la scontistica
|
||||
let recscontistica = await Scontistica.findOne({ idapp, code: prod.sconto2 }).lean();
|
||||
if (!recscontistica) {
|
||||
recscontistica = new Scontistica({ idapp, code: prod.sconto2 });
|
||||
// Non esiste questa scontistica, quindi lo creo !
|
||||
ris = await recscontistica.save();
|
||||
recscontistica = await Scontistica.findOne({ idapp, code: prod.sconto2 }).lean();
|
||||
}
|
||||
|
||||
if (recscontistica) {
|
||||
arrsconti.push(recscontistica);
|
||||
}
|
||||
}
|
||||
|
||||
if (arrsconti.length > 0) {
|
||||
objtoset = {
|
||||
...objtoset,
|
||||
idScontisticas: arrsconti,
|
||||
}
|
||||
setta = true;
|
||||
}
|
||||
|
||||
// Aggiorna il prezzo ?
|
||||
const aggiornaprezzo = false;
|
||||
if (aggiornaprezzo) {
|
||||
@@ -584,6 +636,8 @@ module.exports.singlerecconvert_AfterImport = async function (idapp, prod, isnuo
|
||||
producer_name: 1,
|
||||
provider_name: 1,
|
||||
magazzino_name: 1,
|
||||
sconto1: 1,
|
||||
sconto2: 1,
|
||||
};
|
||||
|
||||
ris = await Product.updateOne({ _id: ObjectID(prod._id) }, { $unset: objDelete })
|
||||
|
||||
@@ -287,6 +287,9 @@ const UserSchema = new mongoose.Schema({
|
||||
manage_telegram: {
|
||||
type: Boolean,
|
||||
},
|
||||
admin_telegram: {
|
||||
type: Boolean,
|
||||
},
|
||||
resplist: {
|
||||
type: Boolean,
|
||||
},
|
||||
@@ -3606,7 +3609,7 @@ UserSchema.statics.getusersAdmin = async function (idapp) {
|
||||
|
||||
// Int32 mongodb 6.0
|
||||
|
||||
return await User.find({ idapp, 'profile.manage_telegram': true, perm: { $bitsAnySet: 0b001 } },
|
||||
return await User.find({ idapp, 'profile.admin_telegram': true, perm: { $bitsAnySet: 0b001 } },
|
||||
{ username: 1, 'profile.teleg_id': 1, perm: 1 }).then((arrrec) => {
|
||||
return (!!arrrec) ? arrrec : null;
|
||||
}).catch((e) => {
|
||||
@@ -3707,7 +3710,7 @@ UserSchema.statics.isAdminByIdTeleg = async function (idapp, idtelegram) {
|
||||
return await User.findOne({
|
||||
idapp,
|
||||
username: 'paoloar77',
|
||||
'profile.manage_telegram': true,
|
||||
'profile.admin_telegram': true,
|
||||
'profile.teleg_id': idtelegram,
|
||||
}, { 'profile.teleg_id': 1 }).then((rec) => {
|
||||
return (!!rec && rec.profile.teleg_id === idtelegram);
|
||||
@@ -5407,6 +5410,7 @@ UserSchema.statics.addNewSite = async function (idappPass, body) {
|
||||
myuser.profile.special_req = true;
|
||||
myuser.profile.nationality = 'IT';
|
||||
myuser.profile.manage_telegram = true;
|
||||
myuser.profile.admin_telegram = true;
|
||||
myuser.profile.teleg_id = MyTelegramBot.ADMIN_IDTELEGRAM_SERVER;
|
||||
myuser.profile.username_telegram = MyTelegramBot.ADMIN_USERNAME_TELEGRAM;
|
||||
myuser.lasttimeonline = new Date();
|
||||
|
||||
@@ -69,23 +69,24 @@ class Cart {
|
||||
async addqty(itemorder) {
|
||||
const myitem = this.items.find((rec) => rec.order._id.toString() === itemorder._id)
|
||||
if (!!myitem) {
|
||||
let step = 1;
|
||||
let stepmin = myitem.order.product.minStepQty | 1;
|
||||
let step = stepmin;
|
||||
if (this.isAvailableByOrder(myitem.order)) {
|
||||
if (myitem.order.quantity === 0)
|
||||
step = myitem.order.product.minBuyQty | 1
|
||||
step = myitem.order.product.minBuyQty | stepmin
|
||||
else if (myitem.order.quantity >= 10)
|
||||
step = 2
|
||||
step = stepmin < 2 ? 2 : stepmin
|
||||
else if (myitem.order.quantity >= 20)
|
||||
step = 5
|
||||
step = stepmin < 5 ? 5 : stepmin
|
||||
|
||||
myitem.order.quantity += step;
|
||||
} else {
|
||||
if (myitem.order.quantitypreordered === 0)
|
||||
step = myitem.order.product.minBuyQty | 1
|
||||
step = myitem.order.product.minBuyQty | stepmin
|
||||
else if (myitem.order.quantitypreordered >= 10)
|
||||
step = 2
|
||||
step = stepmin < 2 ? 2 : stepmin
|
||||
else if (myitem.order.quantitypreordered >= 20)
|
||||
step = 5
|
||||
step = stepmin < 5 ? 5 : stepmin
|
||||
|
||||
myitem.order.quantitypreordered += step;
|
||||
}
|
||||
@@ -99,11 +100,15 @@ class Cart {
|
||||
}
|
||||
|
||||
qtaNextSub(myorder, myproduct) {
|
||||
let step = 1
|
||||
let step = myproduct.minStepQty | 1
|
||||
let minqta = myproduct.minBuyQty | 1
|
||||
if (myproduct.quantityAvailable > 0) {
|
||||
if (myorder.quantity === minqta)
|
||||
step = minqta
|
||||
else{
|
||||
if ((myorder.quantity - step) < 0)
|
||||
step = myorder.quantity - step
|
||||
}
|
||||
} else {
|
||||
if (myorder.quantitypreordered === minqta)
|
||||
step = minqta
|
||||
|
||||
@@ -39,6 +39,7 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
const cmd = req.body.cmd;
|
||||
const idapp = req.body.idapp;
|
||||
const data = req.body.data;
|
||||
const options = req.body.data.options;
|
||||
|
||||
try {
|
||||
const liste = require('../data/liste');
|
||||
@@ -49,8 +50,7 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
});
|
||||
|
||||
} else if (cmd === shared_consts.Cmd.PRODUCTS) {
|
||||
|
||||
let dataObjects = JSON.parse(`[${data}]`);
|
||||
let dataObjects = JSON.parse(`[${data.arrdata}]`);
|
||||
|
||||
let updated = 0;
|
||||
let imported = 0;
|
||||
@@ -72,28 +72,36 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
}
|
||||
|
||||
if (product.cat_name) {
|
||||
arrcat = product.cat_name.trim().split(',');
|
||||
for (const mycat of arrcat) {
|
||||
// Cerca la Categoria
|
||||
let reccateg = await CatProd.findOne({ idapp, name: product.cat_name }).lean();
|
||||
let reccateg = await CatProd.findOne({ idapp, name: mycat }).lean();
|
||||
if (!reccateg) {
|
||||
// Non esiste questo produttore, quindi lo creo !
|
||||
reccateg = new CatProd({ idapp, name: product.cat_name });
|
||||
reccateg = new CatProd({ idapp, name: mycat });
|
||||
ris = await reccateg.save();
|
||||
reccateg = await CatProd.findOne({ idapp, name: product.cat_name }).lean();
|
||||
reccateg = await CatProd.findOne({ idapp, name: mycat }).lean();
|
||||
}
|
||||
|
||||
if (reccateg) {
|
||||
productInfo.idCatProds.push(reccateg._id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!product.hasOwnProperty('active')) {
|
||||
product.active = true;
|
||||
}
|
||||
|
||||
if (product.code)
|
||||
delete product.code;
|
||||
if (product.name)
|
||||
delete product.name;
|
||||
if (product.link)
|
||||
delete product.link;
|
||||
|
||||
let esisteindb = await ProductInfo.findOne({ code: productInfo.code }).lean();
|
||||
|
||||
// Update ProductInfo
|
||||
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: true });
|
||||
if (risrecInfo) {
|
||||
@@ -115,6 +123,11 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
isnuovo = true;
|
||||
}
|
||||
|
||||
if (!options.aggiornaStockQta && esisteindb) {
|
||||
delete product.stockQty;
|
||||
delete product.bookableQty;
|
||||
}
|
||||
|
||||
let risrec = await Product.findOneAndUpdate({ idProductInfo: product.idProductInfo }, { $set: product }, { new: true, upsert: true });
|
||||
|
||||
let recnew = await Product.findOne({ idProductInfo: product.idProductInfo }).lean();
|
||||
|
||||
@@ -87,6 +87,7 @@ const UserCost = {
|
||||
FIELDS_UPDATE_TELEGRAM_BOT: [
|
||||
'profile.teleg_id',
|
||||
'profile.manage_telegram',
|
||||
'profile.admin_telegram',
|
||||
'deleted',
|
||||
'reported',
|
||||
],
|
||||
|
||||
@@ -1977,21 +1977,21 @@ class Telegram {
|
||||
await this.menumsgPaolo(msg);
|
||||
} else if (cmd1 === Menu.EXECSH) {
|
||||
if (rec.user && cmd2) {
|
||||
let isAdmin = rec.user ? rec.user.profile.manage_telegram : false;
|
||||
let isAdmin = rec.user ? rec.user.profile.admin_telegram : false;
|
||||
if (isAdmin) {
|
||||
const ris = await tools.execScript(this.idapp, msg, cmd2, 'Eseguo lo script');
|
||||
}
|
||||
}
|
||||
} else if (cmd1 === Menu.LOG_SRV) {
|
||||
if (rec.user) {
|
||||
let isAdmin = rec.user ? rec.user.profile.manage_telegram : false;
|
||||
let isAdmin = rec.user ? rec.user.profile.admin_telegram : false;
|
||||
if (isAdmin) {
|
||||
await this.menuLogSrv(rec, msg, cmd2);
|
||||
}
|
||||
}
|
||||
} else if (cmd1 === Menu.REBOOT_SRV) {
|
||||
if (rec.user) {
|
||||
let isAdmin = rec.user ? rec.user.profile.manage_telegram : false;
|
||||
let isAdmin = rec.user ? rec.user.profile.admin_telegram : false;
|
||||
if (isAdmin) {
|
||||
await this.menuRebootSrv(rec, msg, cmd2);
|
||||
}
|
||||
@@ -3519,7 +3519,7 @@ class Telegram {
|
||||
// Check if you are Admin
|
||||
const user = await User.UserByIdTelegram(idapp, id);
|
||||
// let isAdmin = user ? user.profile.manage_telegram && user.username === 'paoloar77' : false;
|
||||
let isAdmin = user ? user.profile.manage_telegram : false;
|
||||
let isAdmin = user ? user.profile.admin_telegram : false;
|
||||
const isManager = user ? user.profile.manage_telegram : false;
|
||||
const isVerified = user ? user.profile.teleg_id > 0 && user.verified_by_aportador : false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user