Corretto Ordini e visualizzazione dei Totali
This commit is contained in:
@@ -2,6 +2,7 @@ DATABASE=test_PiuCheBuono
|
||||
UDB=paofreeplanet
|
||||
PDB=mypassword@1A
|
||||
SEND_EMAIL=0
|
||||
SEND_EMAIL_ORDERS=0
|
||||
PORT=3000
|
||||
appTelegram_TEST=["1","13"]
|
||||
appTelegram=["1","13"]
|
||||
@@ -15,6 +16,7 @@ PORT_APP1=8080
|
||||
SIGNCODE=SU2134hncaskjdbo231oihJSDNHEI$1@AB
|
||||
HTTPS_LOCALHOST=true
|
||||
DEBUG=0
|
||||
DEBUG=0
|
||||
TESTING_ON=1
|
||||
LOCALE=1
|
||||
DELAY_SENDEMAIL=2000
|
||||
|
||||
@@ -2,6 +2,7 @@ DATABASE=PiuCheBuono
|
||||
UDB=paofreeplanet
|
||||
PDB=suerteFreePlanet@1A
|
||||
SEND_EMAIL=1
|
||||
SEND_EMAIL_ORDERS=1
|
||||
PORT=3000
|
||||
appTelegram_TEST=["17"]
|
||||
appTelegram=["17"]
|
||||
|
||||
@@ -2,6 +2,7 @@ DATABASE=test_PiuCheBuono
|
||||
UDB=paofreeplanet
|
||||
PDB=suerteFreePlanet@1A
|
||||
SEND_EMAIL=1
|
||||
SEND_EMAIL_ORDERS=1
|
||||
PORT=3001
|
||||
appTelegram_TEST=["17"]
|
||||
appTelegram=["17"]
|
||||
|
||||
@@ -98,7 +98,6 @@ MovementSchema.statics.addMov = async function (idapp, accountFromIdTable, accou
|
||||
|
||||
let mymov = await Movement.create(
|
||||
{
|
||||
_id: new ObjectID().toString(),
|
||||
idapp,
|
||||
transactionDate: new Date(),
|
||||
accountFromId: accountFromIdTable._id,
|
||||
|
||||
@@ -180,14 +180,17 @@ module.exports.getOrderByID = function (id, callback) {
|
||||
}
|
||||
|
||||
module.exports.createOrder = async function (order) {
|
||||
const orderModel = new Order(order);
|
||||
|
||||
return await orderModel.save(order)
|
||||
try {
|
||||
return await Order.create(order)
|
||||
.then((ris) => {
|
||||
if (!!ris)
|
||||
return ris._id;
|
||||
return null;
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('err', e);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.updateStatusOrders = async function (arrOrders, status) {
|
||||
|
||||
@@ -35,7 +35,7 @@ const OrdersCartSchema = new Schema({
|
||||
type: Number,
|
||||
Default: 0,
|
||||
},
|
||||
evaso: { // e quindi è stato tolto dal magazzino (aggiornando il campo StockQty)
|
||||
evaso: { // e quindi è stato tolto dal magazzino (aggiornando il campo stockQty)
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
@@ -141,10 +141,10 @@ module.exports.getStatusCartByUserId = async function (uid, idapp, numorder) {
|
||||
}
|
||||
|
||||
module.exports.getRecCartByUserId = async function (uid, idapp, numorder) {
|
||||
let query = { userId: uid, idapp, status: { $gte: shared_consts.OrderStatus.CHECKOUT_SENT } }
|
||||
let query = { userId: uid, idapp, status: { $lt: shared_consts.OrderStatus.CHECKOUT_SENT } }
|
||||
let myorderscart = null;
|
||||
if (numorder > 0) {
|
||||
query = { userId: uid, idapp, numorder, status: { $gte: shared_consts.OrderStatus.CHECKOUT_SENT } }
|
||||
query = { userId: uid, idapp, numorder, status: { $lt: shared_consts.OrderStatus.CHECKOUT_SENT } }
|
||||
}
|
||||
|
||||
myorderscart = await OrdersCart.findOne(query).lean();
|
||||
@@ -160,6 +160,7 @@ module.exports.getOrdersCartById = async function (id) {
|
||||
}
|
||||
module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder) {
|
||||
|
||||
try {
|
||||
let query = { idapp, status: { $gte: shared_consts.OrderStatus.CHECKOUT_SENT }, deleted: false }
|
||||
let myorderscart = null;
|
||||
if (numorder > 0) {
|
||||
@@ -170,19 +171,21 @@ module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder) {
|
||||
query.userId = uid;
|
||||
}
|
||||
|
||||
myorderscart = await OrdersCart.find(query).populate('items.order')
|
||||
.populate({
|
||||
path: 'items.order',
|
||||
populate: {
|
||||
path: 'idProduct',
|
||||
model: 'Product'
|
||||
},
|
||||
/*transform: function(doc, populated) {
|
||||
// Rinomina 'idProduct' a 'product' nei risultati della popolazione
|
||||
populated.product = populated.idProduct;
|
||||
delete populated.idProduct;
|
||||
return populated;
|
||||
},*/
|
||||
|
||||
myorderscart = await OrdersCart.find(query)
|
||||
.populate('items.order')
|
||||
.populate({
|
||||
path: 'items.order',
|
||||
populate: {
|
||||
path: 'idProduct',
|
||||
model: 'Product'
|
||||
},
|
||||
})
|
||||
.populate({
|
||||
path: 'items.order',
|
||||
@@ -204,127 +207,44 @@ module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder) {
|
||||
path: 'idStorehouse',
|
||||
model: 'Storehouse'
|
||||
},
|
||||
/*transform: function(doc, populated) {
|
||||
// Rinomina 'idProduct' a 'product' nei risultati della popolazione
|
||||
populated.storehouse = populated.idStorehouse;
|
||||
delete populated.idStorehouse;
|
||||
return populated;
|
||||
},*/
|
||||
})
|
||||
.populate('userId').lean();
|
||||
.populate({
|
||||
path: 'userId',
|
||||
model: 'User',
|
||||
select: '_id name surname username profile', // Specify the fields you want to retrieve
|
||||
})
|
||||
.lean();
|
||||
|
||||
myorderscart = myorderscart.map(order => {
|
||||
order.user = order.userId
|
||||
order.userId = order.user._id
|
||||
order.items = order.items.map(item => {
|
||||
if (item.order) {
|
||||
try {
|
||||
item.order.product = item.order.idProduct;
|
||||
delete item.order.idProduct;
|
||||
item.order.idProduct = item.order.product._id;
|
||||
item.order.producer = item.order.idProducer;
|
||||
delete item.order.idProducer;
|
||||
item.order.idProducer = item.order.producer._id;
|
||||
item.order.storehouse = item.order.idStorehouse;
|
||||
delete item.order.idStorehouse;
|
||||
item.order.idStorehouse = item.order.storehouse._id;
|
||||
item.order.provider = item.order.idProvider;
|
||||
delete item.order.idProvider;
|
||||
item.order.idProvider = item.order.provider._id;
|
||||
} catch (e) {
|
||||
console.error('Err: ', e);
|
||||
}
|
||||
}
|
||||
return item;
|
||||
});
|
||||
return order;
|
||||
});
|
||||
|
||||
/*for (let ind = 0; ind < myorderscart.length; ind++) {
|
||||
for (const idkey in myorderscart[ind].items) {
|
||||
try {
|
||||
let idorder = myorderscart[ind].items[idkey]._id.toString();
|
||||
const myorder = myorderscart[ind].items[idkey].order;
|
||||
if (!!myorder) {
|
||||
idorder = myorderscart[ind].items[idkey].order._id.toString();
|
||||
}
|
||||
// myorderscart[ind].nameSurname = await User.getNameSurnameById(idapp, myorderscart[ind].userId);
|
||||
// const myord = await Order.getTotalOrderById(idorder);
|
||||
// if (myord.length > 0) {
|
||||
// myorderscart[ind].items[idkey].order = myord[0];
|
||||
// }
|
||||
} catch (e) {
|
||||
console.log('err', e);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
/* if (!!mycart) {
|
||||
for (const idkey in mycart.items) {
|
||||
try {
|
||||
idorder = mycart.items[idkey]._id.toString();
|
||||
const myorder = mycart.items[idkey].order;
|
||||
if (!!myorder) {
|
||||
idorder = mycart.items[idkey].order._id.toString();
|
||||
}
|
||||
const myord = await Order.getTotalOrderById(idorder);
|
||||
if (myord.length > 0) {
|
||||
mycart.items[idkey]._doc.order = myord[0];
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('err', e);
|
||||
}
|
||||
}
|
||||
return mycart;
|
||||
}*/
|
||||
return myorderscart
|
||||
} catch (e) {
|
||||
console.error('Err:', e);
|
||||
}
|
||||
// return null;
|
||||
}
|
||||
|
||||
module.exports.getOrdersCartByDepartmentId = async function (depId, idapp) {
|
||||
let query = {
|
||||
idapp, status: { $gte: shared_consts.OrderStatus.CHECKOUT_SENT },
|
||||
deleted: false,
|
||||
}
|
||||
const myorderscart = await OrdersCart.find(query).lean();
|
||||
|
||||
for (let ind = 0; ind < myorderscart.length; ind++) {
|
||||
for (const idkey in myorderscart[ind].items) {
|
||||
try {
|
||||
let idorder = myorderscart[ind].items[idkey]._id.toString();
|
||||
const myorder = myorderscart[ind].items[idkey].order;
|
||||
if (!!myorder) {
|
||||
idorder = myorderscart[ind].items[idkey].order._id.toString();
|
||||
}
|
||||
myorderscart[ind].nameSurname = await User.getNameSurnameById(idapp, myorderscart[ind].userId);
|
||||
const myord = await Order.getTotalOrderById(idorder);
|
||||
if (myord.length > 0) {
|
||||
myorderscart[ind].items[idkey].order = myord[0];
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('err', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return myorderscart
|
||||
// return null;
|
||||
}
|
||||
|
||||
module.exports.getOrderById = async function (Id, idapp) {
|
||||
let query = { _id: Id, idapp, status: { $gte: shared_consts.OrderStatus.CHECKOUT_SENT } }
|
||||
const myorderscart = await OrdersCart.find(query).lean();
|
||||
|
||||
for (let ind = 0; ind < myorderscart.length; ind++) {
|
||||
for (const idkey in myorderscart[ind].items) {
|
||||
try {
|
||||
let idorder = myorderscart[ind].items[idkey]._id.toString();
|
||||
const myorder = myorderscart[ind].items[idkey].order;
|
||||
if (!!myorder) {
|
||||
idorder = myorderscart[ind].items[idkey].order._id.toString();
|
||||
}
|
||||
myorderscart[ind].nameSurname = await User.getNameSurnameById(idapp, myorderscart[ind].userId);
|
||||
const myord = await Order.getTotalOrderById(idorder);
|
||||
if (myord.length > 0) {
|
||||
myorderscart[ind].items[idkey].order = myord[0];
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('err', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return myorderscart
|
||||
// return null;
|
||||
}
|
||||
|
||||
module.exports.updateOrdersCartById = function (id, newOrdersCart, callback) {
|
||||
let query = {
|
||||
@@ -362,6 +282,20 @@ module.exports.updateOrdersCartById = function (id, newOrdersCart, callback) {
|
||||
|
||||
module.exports.setFieldInOrdersById = async function (objtoset, myOrderCart) {
|
||||
|
||||
try {
|
||||
let ris2 = null;
|
||||
// Imposta su tutti i singoli prodotti ordinati (Order)
|
||||
for (const recitem of myOrderCart.items) {
|
||||
ris2 = await Order.findOneAndUpdate(
|
||||
{ _id: recitem.order._id },
|
||||
{
|
||||
$set: objtoset
|
||||
},
|
||||
{ new: false }
|
||||
)
|
||||
// console.log('ris', ris2);
|
||||
}
|
||||
|
||||
const ris = await OrdersCart.findOneAndUpdate(
|
||||
{ _id: myOrderCart._id },
|
||||
{
|
||||
@@ -370,15 +304,8 @@ module.exports.setFieldInOrdersById = async function (objtoset, myOrderCart) {
|
||||
{ new: false }
|
||||
)
|
||||
|
||||
// Imposta su tutti i singoli prodotti ordinati (Order)
|
||||
for (const order of myOrderCart.items) {
|
||||
await Order.findOneAndUpdate(
|
||||
{ _id: order._id },
|
||||
{
|
||||
$set: objtoset
|
||||
},
|
||||
{ new: false }
|
||||
)
|
||||
} catch (e) {
|
||||
console.log('Err', e);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -463,7 +390,6 @@ module.exports.updateStockQtaDalMagazzino = async function (idorderscart) {
|
||||
|
||||
if (myorderscart) {
|
||||
for (const idkey in myorderscart.items) {
|
||||
let idorder = myorderscart.items[idkey]._id;
|
||||
let order = myorderscart.items[idkey].order;
|
||||
|
||||
if (!order.evaso) {
|
||||
|
||||
@@ -92,10 +92,6 @@ const productSchema = new Schema({
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
quantityAvailable: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
quantityLow: { //Soglia disponibilità bassa
|
||||
type: Number,
|
||||
default: 0,
|
||||
@@ -167,16 +163,48 @@ module.exports.executeQueryTable = function (idapp, params) {
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
module.exports.findAllIdApp = async function (idapp, code) {
|
||||
let myfind = { idapp, active: true };
|
||||
module.exports.getProductByCode = function (idapp, code) {
|
||||
return Product.findAllIdApp(idapp, code);
|
||||
}
|
||||
|
||||
module.exports.getProductById = async function (id) {
|
||||
const arrris = await Product.findAllIdApp('', '', id);
|
||||
return arrris && arrris.length > 0 ? arrris[0] : null
|
||||
}
|
||||
|
||||
module.exports.findAllIdApp = async function (idapp, code, id) {
|
||||
let myfind = {};
|
||||
let myqueryadd = {};
|
||||
let query = [];
|
||||
|
||||
try {
|
||||
|
||||
if (idapp)
|
||||
myfind = { idapp, active: true };
|
||||
|
||||
if (code) {
|
||||
myfind = { ...myfind, code }
|
||||
}
|
||||
if (id) {
|
||||
myqueryadd = {
|
||||
$addFields: {
|
||||
myId1: {
|
||||
$toObjectId: id,
|
||||
},
|
||||
},
|
||||
}
|
||||
myfind = {
|
||||
$expr: {
|
||||
$eq: ["$_id", "$myId1"],
|
||||
},
|
||||
}
|
||||
|
||||
query.push(myqueryadd);
|
||||
}
|
||||
|
||||
// return await Product.find(myfind);
|
||||
|
||||
const query = [
|
||||
query.push(
|
||||
{ $match: myfind },
|
||||
{
|
||||
$lookup: {
|
||||
@@ -244,12 +272,16 @@ module.exports.findAllIdApp = async function (idapp, code) {
|
||||
$unset: 'productOrders'
|
||||
},
|
||||
|
||||
];
|
||||
);
|
||||
|
||||
let ris = await Product.aggregate(query)
|
||||
|
||||
return ris;
|
||||
|
||||
} catch (e) {
|
||||
console.error('E', e);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -269,10 +301,6 @@ module.exports.getProductByTitle = function (query, sort, callback) {
|
||||
Product.find(query, null, sort, callback)
|
||||
}
|
||||
|
||||
module.exports.getProductByCode = function (idapp, code) {
|
||||
return Product.findOne({ idapp, code })
|
||||
}
|
||||
|
||||
module.exports.filterProductByDepartment = function (department, callback) {
|
||||
let regexp = new RegExp(`^${department}$`, 'i')
|
||||
var query = { department: { $regex: regexp } };
|
||||
|
||||
@@ -55,20 +55,27 @@ router.post('/:userId', authenticate, async function (req, res, next) {
|
||||
let order = req.body.order;
|
||||
|
||||
try {
|
||||
const mycart = await Cart.getCartByUserId(userId, idapp);
|
||||
let mycart = await Cart.getCartByUserId(userId, idapp);
|
||||
|
||||
// const myorder = Order.getOrderByID(order._id);
|
||||
if (!addqty && !subqty)
|
||||
order._id = await Order.createOrder(order);
|
||||
|
||||
let cart = null;
|
||||
let product = null;
|
||||
// no cart save empty cart to database then return response
|
||||
let myqty = 0;
|
||||
let nuovo = false;
|
||||
if (!mycart) {
|
||||
let oldCart = new CartClass(order)
|
||||
cart = await Cart.createCart(oldCart.generateModel());
|
||||
} else {
|
||||
|
||||
mycart = await Cart.getCartByUserId(userId, idapp);
|
||||
nuovo = true;
|
||||
}
|
||||
|
||||
let newCart = CartClass.constructByCart(mycart);
|
||||
if (!nuovo) {
|
||||
if (addqty) {
|
||||
myqty = await newCart.addqty(order);
|
||||
} else if (subqty) {
|
||||
@@ -76,11 +83,19 @@ router.post('/:userId', authenticate, async function (req, res, next) {
|
||||
} else {
|
||||
const ind = newCart.addItem(order);
|
||||
}
|
||||
cart = await Cart.updateCartByCartId(mycart._id, newCart.generateModel());
|
||||
} else {
|
||||
await newCart.updatetotals();
|
||||
}
|
||||
cart = await Cart.updateCartByCartId(mycart._id, newCart.generateModel());
|
||||
|
||||
|
||||
if (cart) {
|
||||
const carttot = await Cart.getCartByUserId(userId, idapp);
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, cart: carttot, qty: myqty });
|
||||
if (order.idProduct)
|
||||
product = await Product.getProductById(order.idProduct);
|
||||
else if (order.product)
|
||||
product = await Product.getProductById(order.product._id);
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, cart: carttot, qty: myqty, product });
|
||||
} else {
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, cart: null });
|
||||
}
|
||||
@@ -112,6 +127,12 @@ router.delete('/:userId', authenticate, async function (req, res) {
|
||||
|
||||
const mycart = await Cart.getCartByUserId(userId, idapp);
|
||||
|
||||
const ord = await Order.findOne({ _id: orderId });
|
||||
let idProduct = ''
|
||||
let product = null;
|
||||
if (ord)
|
||||
idProduct = ord.idProduct;
|
||||
|
||||
// Rimuovere l'Ordine
|
||||
const recremoved = await Order.deleteOne({ _id: orderId });
|
||||
if (recremoved) {
|
||||
@@ -124,8 +145,12 @@ router.delete('/:userId', authenticate, async function (req, res) {
|
||||
|
||||
carttot = await Cart.getCartByUserId(userId, idapp);
|
||||
|
||||
if (idProduct) {
|
||||
product = await Product.getProductById(idProduct);
|
||||
}
|
||||
|
||||
console.log('carttot', carttot)
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, cart: carttot });
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, cart: carttot, product });
|
||||
}
|
||||
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, cart: null });
|
||||
@@ -140,17 +165,17 @@ router.put('/:userId', authenticate, async function (req, res, next) {
|
||||
|
||||
try {
|
||||
|
||||
await Cart.getCartByUserId(userId, function (err, c) {
|
||||
await Cart.getCartByUserId(userId, async function (err, c) {
|
||||
if (err) return next(err)
|
||||
let oldCart = new CartClass(c[0] || {})
|
||||
let oldCart = new CartClass(c || {})
|
||||
|
||||
Product.getProductByID(productId, function (err, p) {
|
||||
await Product.getProductByID(productId, async function (err, p) {
|
||||
if (err) return next(err)
|
||||
let newCart = oldCart.add(p, productId, { color, size })
|
||||
|
||||
//exist cart in databse
|
||||
if (c.length > 0) {
|
||||
Cart.updateCartByUserId(
|
||||
await Cart.updateCartByUserId(
|
||||
userId,
|
||||
{
|
||||
items: newCart.items,
|
||||
@@ -164,13 +189,13 @@ router.put('/:userId', authenticate, async function (req, res, next) {
|
||||
})
|
||||
} else {
|
||||
//no cart in database
|
||||
newCart = new Cart({
|
||||
let newCartobj = {
|
||||
items: newCart.items,
|
||||
totalQty: newCart.totalQty,
|
||||
totalPrice: newCart.totalPrice,
|
||||
userId: userId
|
||||
})
|
||||
Cart.createCart(newCart, function (err, resultCart) {
|
||||
}
|
||||
await Cart.createCart(newCartobj, function (err, resultCart) {
|
||||
if (err) return next(err)
|
||||
res.status(201).json(resultCart)
|
||||
})
|
||||
@@ -178,7 +203,9 @@ router.put('/:userId', authenticate, async function (req, res, next) {
|
||||
})
|
||||
})
|
||||
|
||||
return res.send({ code: server_constants.RIS_CODE_OK });
|
||||
const product = await Product.getProductById(productId);
|
||||
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, product });
|
||||
} catch (e) {
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, status: 0 });
|
||||
}
|
||||
@@ -192,6 +219,7 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
|
||||
let userId = req.params.userId;
|
||||
const user = req.user;
|
||||
let status = req.body.status;
|
||||
let note = req.body.note;
|
||||
|
||||
try {
|
||||
const mycart = await Cart.findOne({ _id: cart_id });
|
||||
@@ -213,7 +241,7 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
|
||||
totalPrice: mycart.totalPrice,
|
||||
userId,
|
||||
status,
|
||||
note: mycart.note,
|
||||
note,
|
||||
numorder,
|
||||
created_at: new Date(),
|
||||
modify_at: new Date(),
|
||||
@@ -221,6 +249,8 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
|
||||
}
|
||||
statusOrderCart = myorderCart.status;
|
||||
|
||||
const idordercart = myorderCart._id;
|
||||
|
||||
if (!!mycart) {
|
||||
if (status === shared_consts.OrderStatus.CHECKOUT_SENT) {
|
||||
|
||||
@@ -246,7 +276,7 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
|
||||
// Invia la email dell'Ordine
|
||||
sendemail.sendEmail_OrderProduct(user.lang, idapp, orders[0], user)
|
||||
.then(async (ris) => {
|
||||
myorderCart = await OrdersCart.getRecCartByUserId(userId, idapp, numorder);
|
||||
myorderCart = await OrdersCart.findById(idordercart).lean();
|
||||
return res.send({
|
||||
code: server_constants.RIS_CODE_OK,
|
||||
status: myris.status,
|
||||
|
||||
@@ -12,6 +12,7 @@ var { authenticate, auth_default } = require('../middleware/authenticate');
|
||||
const _ = require('lodash');
|
||||
|
||||
const Product = require('../models/product');
|
||||
const OrdersCart = require('../models/orderscart');
|
||||
const Variant = require('../models/variant');
|
||||
|
||||
/*const Department = require('../models/Department')
|
||||
@@ -27,11 +28,13 @@ const Cart = require('../models/cart');
|
||||
//GET /products
|
||||
router.post('/', auth_default, async function (req, res, next) {
|
||||
const idapp = req.body.idapp;
|
||||
let userId = req.body.userId;
|
||||
|
||||
var products = await Product.findAllIdApp(idapp, "");
|
||||
var orders = await OrdersCart.getOrdersCartByUserId(userId, idapp, 0);
|
||||
|
||||
if (products)
|
||||
res.send({ code: server_constants.RIS_CODE_OK, products });
|
||||
res.send({ code: server_constants.RIS_CODE_OK, products, orders });
|
||||
else
|
||||
res.status(400).send(e);
|
||||
|
||||
|
||||
@@ -742,9 +742,12 @@ module.exports = {
|
||||
|
||||
sendEmail_OrderProduct: async function (lang, idapp, orders, user) {
|
||||
|
||||
try {
|
||||
const msginizio = 'Ordine n: ' + orders.numorder + ' ' + user.name + ' ' + user.surname;
|
||||
console.log(msginizio);
|
||||
|
||||
if (process.env.SEND_EMAIL_ORDERS === '1') {
|
||||
|
||||
await telegrambot.sendMsgTelegramToTheManagers(idapp, msginizio);
|
||||
|
||||
let mylocalsconf = {
|
||||
@@ -762,13 +765,22 @@ module.exports = {
|
||||
|
||||
this.sendEmail_base_e_manager(idapp, 'ecommerce/makeorder/' + lang, mylocalsconf.emailto, mylocalsconf,
|
||||
mylocalsconf.dataemail.email_reply);
|
||||
} else {
|
||||
console.log('Invio Email non eseguito perchè sei in TEST !');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Err:', e);
|
||||
}
|
||||
|
||||
},
|
||||
sendEmail_Order: async function (lang, idapp, orders, user, ordertype, status) {
|
||||
|
||||
try {
|
||||
const msginizio = 'INIZIO - sendEmail_Order ' + ordertype + ': ' + tools.getNomeAppByIdApp(idapp);
|
||||
console.log(msginizio);
|
||||
|
||||
if (process.env.SEND_EMAIL_ORDERS === '1') {
|
||||
|
||||
await telegrambot.sendMsgTelegramToTheManagers(idapp, msginizio);
|
||||
|
||||
let mylocalsconf = {
|
||||
@@ -794,6 +806,13 @@ module.exports = {
|
||||
this.sendEmail_base('ecommerce/' + ordertype + '/' + lang, tools.getManagerEmailByIdApp(idapp), mylocalsconf, '');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log('Invio Email non eseguito perchè sei in TEST !');
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error('Err:', e);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user