- aggiunto note 'note_ordine_gas'
- corretto bug
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
DATABASE=test_FreePlanet
|
||||
DATABASE=test_PiuCheBuono
|
||||
UDB=paofreeplanet
|
||||
PDB=mypassword@1A
|
||||
SEND_EMAIL=0
|
||||
SEND_EMAIL_ORDERS=1
|
||||
PORT=3000
|
||||
appTelegram_TEST=["1","13"]
|
||||
appTelegram=["1","13"]
|
||||
appTelegram_TEST=["1","17"]
|
||||
appTelegram=["1","17"]
|
||||
DOMAIN=mongodb://localhost:27017/
|
||||
AUTH_MONGODB=true
|
||||
MONGODB_USER=admin
|
||||
|
||||
@@ -30,6 +30,9 @@ const CartSchema = new Schema({
|
||||
note: {
|
||||
type: String,
|
||||
},
|
||||
note_ordine_gas: {
|
||||
type: String,
|
||||
},
|
||||
modify_at: {
|
||||
type: Date,
|
||||
},
|
||||
@@ -121,6 +124,7 @@ module.exports.updateCartByCartId = async function (cartId, newCart) {
|
||||
const totalPrice = newCart.totalPrice;
|
||||
const totalPriceCalc = newCart.totalPriceCalc;
|
||||
const note = newCart.note;
|
||||
const note_ordine_gas = newCart.note_ordine_gas;
|
||||
|
||||
const modify_at = new Date();
|
||||
|
||||
@@ -131,6 +135,7 @@ module.exports.updateCartByCartId = async function (cartId, newCart) {
|
||||
totalPriceCalc,
|
||||
totalQty,
|
||||
note,
|
||||
note_ordine_gas,
|
||||
modify_at: new Date(),
|
||||
},
|
||||
}, { new: false }).lean().then((ris) => {
|
||||
|
||||
@@ -34,6 +34,9 @@ const gasordineSchema = new Schema({
|
||||
img: {
|
||||
type: String,
|
||||
},
|
||||
note_ordine_gas: {
|
||||
type: String,
|
||||
},
|
||||
|
||||
dataora_chiusura_ordini: {
|
||||
type: Date,
|
||||
|
||||
@@ -94,6 +94,9 @@ const OrdersCartSchema = new Schema({
|
||||
note_per_gestore: {
|
||||
type: String
|
||||
},
|
||||
note_ordine_gas: {
|
||||
type: String
|
||||
},
|
||||
note_per_admin: {
|
||||
type: String
|
||||
},
|
||||
@@ -1079,7 +1082,8 @@ module.exports.updateOrdersCartTotals = async function (idOrdersCart, update) {
|
||||
|
||||
let newOrdersCart = CartClass.constructByCart(orderscart);
|
||||
|
||||
await newOrdersCart.updatecarttotals(false);
|
||||
newOrdersCart.updatecarttotals(false);
|
||||
await newOrdersCart.updateExtraOrder();
|
||||
|
||||
if (update) {
|
||||
await OrdersCart.findOneAndUpdate({ _id: idOrdersCart }, {
|
||||
|
||||
@@ -3,6 +3,8 @@ const cartModel = require('../models/cart')
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
const Gasordine = require('../models/gasordine');
|
||||
|
||||
const Order = require('../models/order');
|
||||
|
||||
class Cart {
|
||||
@@ -33,6 +35,7 @@ class Cart {
|
||||
mynewcart.department = cart.department;
|
||||
mynewcart.userId = cart.userId || "";
|
||||
mynewcart.modify_at = new Date();
|
||||
mynewcart.note_ordine_gas = '';
|
||||
|
||||
return mynewcart;
|
||||
} catch (e) {
|
||||
@@ -100,6 +103,7 @@ class Cart {
|
||||
myitem.order = Order.updateTotals(myitem.order);
|
||||
|
||||
this.updatecarttotals(false);
|
||||
await this.updateExtraOrder();
|
||||
await Order.findOneAndUpdate({ _id: myitem.order._id }, { $set: myitem.order }, { new: false });
|
||||
return myitem.order;
|
||||
}
|
||||
@@ -138,6 +142,7 @@ class Cart {
|
||||
}
|
||||
myitem.order = Order.updateTotals(myitem.order);
|
||||
this.updatecarttotals(false);
|
||||
await this.updateExtraOrder();
|
||||
|
||||
await Order.findOneAndUpdate({ _id: myitem.order._id }, { $set: myitem.order }, { new: false });
|
||||
return myitem.order;
|
||||
@@ -148,7 +153,7 @@ class Cart {
|
||||
}
|
||||
|
||||
|
||||
addItem(itemorder) {
|
||||
async addItem(itemorder) {
|
||||
// this.items.push(itemorder);
|
||||
|
||||
let ind = this.items.length;
|
||||
@@ -156,14 +161,16 @@ class Cart {
|
||||
this.items[ind].order = itemorder;
|
||||
this.items[ind].order = Order.updateTotals(this.items[ind].order);
|
||||
this.updatecarttotals(false);
|
||||
await this.updateExtraOrder();
|
||||
|
||||
return ind;
|
||||
}
|
||||
|
||||
removeItem(orderId) {
|
||||
async removeItem(orderId) {
|
||||
// this.items.push(itemorder);
|
||||
this.items = this.items.filter(item => item.order._id.toString() !== orderId.toString());
|
||||
this.updatecarttotals(false);
|
||||
await this.updateExtraOrder();
|
||||
}
|
||||
|
||||
generateModel() {
|
||||
@@ -177,6 +184,7 @@ class Cart {
|
||||
userId: this.userId,
|
||||
department: this.department,
|
||||
note: this.note,
|
||||
note_ordine_gas: this.note_ordine_gas,
|
||||
modify_at: this.modify_at
|
||||
})
|
||||
return newCart
|
||||
@@ -271,6 +279,39 @@ class Cart {
|
||||
|
||||
}
|
||||
|
||||
async updateExtraOrder() {
|
||||
try {
|
||||
|
||||
let arrGas = [];
|
||||
const precnoteordgas = this.note_ordine_gas
|
||||
this.note_ordine_gas = '';
|
||||
for (const rec in this.items) {
|
||||
let order = this.items[rec].order;
|
||||
if (!order) {
|
||||
order = this.items[rec];
|
||||
}
|
||||
// Prendo la nota valida e la metto visibile sul Carrello !
|
||||
if (order.idGasordine) {
|
||||
const recGas = await Gasordine.findOne({ _id: order.idGasordine }).lean();
|
||||
if (recGas) {
|
||||
if (recGas.note_ordine_gas) {
|
||||
if (!arrGas.includes(recGas._id.toString())) {
|
||||
if (this.note_ordine_gas)
|
||||
this.note_ordine_gas += '<br>'
|
||||
|
||||
this.note_ordine_gas += '<strong>' + recGas.name + '</strong>' + ':<br>' + recGas.note_ordine_gas;
|
||||
arrGas.push(recGas._id.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error('Err:', e);
|
||||
}
|
||||
}
|
||||
|
||||
generateArray() {
|
||||
let arr = [];
|
||||
for (let id in this.items) {
|
||||
|
||||
@@ -179,5 +179,11 @@ module.exports = {
|
||||
"label" : "Bitcoin",
|
||||
"__v" : 0
|
||||
},
|
||||
{
|
||||
"_id" : ObjectID("51bc482667de9a1f64b255ff"),
|
||||
"idapp" : "13",
|
||||
"label" : "Banca del Tempo",
|
||||
"__v" : 0
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
@@ -472,6 +472,7 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!rec.hasOwnProperty('active')) {
|
||||
product.active = true;
|
||||
}
|
||||
@@ -508,6 +509,13 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
recGas = await Gasordine.findOne({ idapp, name: rec.gas_name }).lean();
|
||||
}
|
||||
|
||||
if (recGas) {
|
||||
if (rec.hasOwnProperty('note_ordine_gas')) {
|
||||
const note_ordine_gas = rec['note_ordine_gas'];
|
||||
await Gasordine.findOneAndUpdate({ _id: recGas._id }, { $set: { note_ordine_gas } });
|
||||
}
|
||||
}
|
||||
|
||||
let recProductExist = null;
|
||||
let queryprod = { idProductInfo: product.idProductInfo };
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ router.post('/:userId', authenticate, async function (req, res, next) {
|
||||
} else if (subqty) {
|
||||
myord = await newCart.subqty(order);
|
||||
} else {
|
||||
const ind = newCart.addItem(order);
|
||||
const ind = await newCart.addItem(order);
|
||||
const arrord = await Order.getTotalOrderById(order._id);
|
||||
myord = arrord ? arrord[0] : null;
|
||||
}
|
||||
@@ -104,7 +104,8 @@ router.post('/:userId', authenticate, async function (req, res, next) {
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, cart: null, myord: null, msgerr: 'Non è possibile acquistare nello stesso ordine, su negozi differenti!' });
|
||||
}
|
||||
} else {
|
||||
await newCart.updatecarttotals(true);
|
||||
newCart.updatecarttotals(true);
|
||||
await newCart.updateExtraOrder();
|
||||
const arrord = await Order.getTotalOrderById(order._id);
|
||||
myord = arrord ? arrord[0] : null;
|
||||
}
|
||||
@@ -162,7 +163,7 @@ router.delete('/:userId', authenticate, async function (req, res) {
|
||||
// Rimuovere l'id sul Carrello
|
||||
|
||||
let newCart = CartClass.constructByCart(mycart);
|
||||
newCart.removeItem(orderId);
|
||||
await newCart.removeItem(orderId);
|
||||
let carttot = null;
|
||||
const cart = await Cart.updateCartByCartId(mycart._id, newCart.generateModel());
|
||||
|
||||
@@ -276,6 +277,7 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
|
||||
totalQty: mycart.totalQty,
|
||||
totalPrice: mycart.totalPrice,
|
||||
totalPriceCalc: mycart.totalPriceCalc,
|
||||
note_ordine_gas: mycart.note_ordine_gas,
|
||||
userId,
|
||||
status,
|
||||
note,
|
||||
|
||||
@@ -851,10 +851,9 @@ router.patch('/chval', authenticate, async (req, res) => {
|
||||
|
||||
// tools.mylogshow('PATCH CHVAL: ', id, fieldsvalue);
|
||||
|
||||
req.user.perm = 0;
|
||||
|
||||
// If I change my record...
|
||||
if (((!User.isAdmin(req.user.perm)
|
||||
if ((
|
||||
(!User.isAdmin(req.user.perm)
|
||||
&& !User.isManager(req.user.perm)
|
||||
&& !User.isEditor(req.user.perm)
|
||||
&& !User.isFacilitatore(req.user.perm))
|
||||
|
||||
@@ -518,8 +518,9 @@ async function inizia() {
|
||||
|
||||
try {
|
||||
if (true) {
|
||||
const url = 'https://raw.githubusercontent.com/matteocontrini/comuni-json/master/comuni.json';
|
||||
const outputPath = './comuni_italia_geojson.json';
|
||||
downloadGeoJSON('', outputPath);
|
||||
downloadGeoJSON(url, outputPath);
|
||||
}
|
||||
|
||||
mycron_everyday();
|
||||
|
||||
Reference in New Issue
Block a user