Compare commits
11 Commits
beforeRisI
...
1.0.20
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e42baf79e | ||
|
|
e3ed2934ee | ||
|
|
e895e7dae2 | ||
|
|
4a408b4ebd | ||
|
|
0e3ba5ff87 | ||
|
|
a66cd610dd | ||
|
|
5aa6accfc5 | ||
|
|
35178684af | ||
|
|
bba0df4302 | ||
|
|
f1954d98d6 | ||
|
|
34b00bdf98 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -28,3 +28,5 @@ src/server/.DS_Store
|
||||
emails/.DS_Store
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
logtrans.txt
|
||||
|
||||
22
logtrans.txt
22
logtrans.txt
@@ -96,4 +96,24 @@ PaoTEST1: 10 RIS]
|
||||
Gio 12/10 ORE 08:06: [<b>Circuito RIS Rimini</b>]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
|
||||
Saldi:
|
||||
paoloar77: -18 RIS]
|
||||
SuryaArena2: 7 RIS]
|
||||
SuryaArena2: 7 RIS]
|
||||
Mer 29/11 ORE 16:35: [<b>Circuito RIS Italia</b>]: Inviate Monete da SuryaArena a paoloar77 5 RIS [causale: Seconda]
|
||||
Saldi:
|
||||
SuryaArena: -5 RIS]
|
||||
paoloar77: 5 RIS]
|
||||
Mer 29/11 ORE 16:44: [<b>Circuito RIS Italia</b>]: Inviate Monete da SuryaArena a paoloar77 3 RIS [causale: Eccolo]
|
||||
Saldi:
|
||||
SuryaArena: -8 RIS]
|
||||
paoloar77: 8 RIS]
|
||||
Mer 29/11 ORE 16:50: [<b>Circuito RIS Italia</b>]: Inviate Monete da SuryaArena a paoloar77 3 RIS [causale: Ricevuto un bel massaggio]
|
||||
Saldi:
|
||||
SuryaArena: -11 RIS]
|
||||
paoloar77: 11 RIS]
|
||||
Mer 29/11 ORE 16:52: [<b>Circuito RIS Bologna</b>]: Inviate Monete da SuryaArena a paoloar77 4 RIS [causale: Un bel massaggio con olio caldo]
|
||||
Saldi:
|
||||
SuryaArena: -4 RIS]
|
||||
paoloar77: 14 RIS]
|
||||
Mer 29/11 ORE 17:14: [<b>Circuito RIS Italia</b>]: Inviate Monete da SuryaArena a paoloar77 2 RIS [causale: Massaggio !]
|
||||
Saldi:
|
||||
SuryaArena: -13 RIS]
|
||||
paoloar77: 13 RIS]
|
||||
@@ -5,6 +5,9 @@
|
||||
},
|
||||
{
|
||||
"path": "../../../newfreeplanet"
|
||||
},
|
||||
{
|
||||
"path": "../../../cnm"
|
||||
}
|
||||
],
|
||||
"settings": {
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
"CIRCUIT_EXIT_USER": "❌ l'utente %s è uscito dal '%s'",
|
||||
"CIRCUIT_EXIT_USER_TO_ME": "❌ Sei uscito dal '%s'",
|
||||
"CIRCUIT_REMOVED_TO_ME": "❌ Sei stato rimosso dal '%s' (da parte di %s)",
|
||||
"CIRCUIT_SENDCOINSREQ": "%s ti sta inviando <strong>%s %s</strong> sul '%s'.",
|
||||
"CIRCUIT_SENDCOINSREQ": "%s ti sta inviando <strong>%s %s</strong> sul <strong>'%s'</strong>",
|
||||
"COMUNITARIO": "Comunitario",
|
||||
"COLLETTIVO": "Gruppo",
|
||||
"CIRCUIT_SENDCOINSREQ_GROUP": "%s sta inviando <strong>%s %s</strong> al Conto %s '%s' sul '%s'.",
|
||||
@@ -107,5 +107,11 @@
|
||||
"DATEDAYONLY": "%s dalle %s alle %s",
|
||||
"DATE_2DAYS": "%s dalle %s fino a %s alle %s",
|
||||
"SENDMSG_ENTRA_IN_RISO_ITALIA": "Ciao %s!<br>%s che appartiene al <em>%s</em> vuole inviarti dei RIS. Per poterli ricevere dovete entrambi utilizzare il <strong>Circuito RIS Italia</strong>.",
|
||||
"CLICCA_QUI": "CLICCA QUI"
|
||||
"CLICCA_QUI": "CLICCA QUI",
|
||||
"✅ %s è stato Abilitato correttamente (da %s)!": "✅ %s è stato Abilitato correttamente (da %s)!",
|
||||
"✅ Sei stato Abilitato correttamente da %s!": "✅ Sei stato Abilitato correttamente da %s!",
|
||||
"🚫 Hai rifiutato l'accesso alla App di RISO da parte di %s!": "🚫 Hai rifiutato l'accesso alla App di RISO da parte di %s!",
|
||||
"🚫 Ti è stato rifiutato l'accesso. Probabilmente l'username con cui ti sei registrato non ti conosce. (%s) !<br>Contatta l'Assistenza Tecnica.": "🚫 Ti è stato rifiutato l'accesso. Probabilmente l'username con cui ti sei registrato non ti conosce. (%s) !<br>Contatta l'Assistenza Tecnica.",
|
||||
"🚫 %s ha rifiutato l'accesso alla App a %s !": "🚫 %s ha rifiutato l'accesso alla App a %s !",
|
||||
"✅ Hai Abilitato l'accesso alla App a %s !": "✅ Hai Abilitato l'accesso alla App a %s !"
|
||||
}
|
||||
@@ -9,16 +9,16 @@ const CartSchema = new Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
},
|
||||
userId: {type: Schema.Types.ObjectId, ref: 'User'},
|
||||
totalQty: {type: Number, default: 0},
|
||||
totalPrice: {type: Number, default: 0},
|
||||
userId: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||
totalQty: { type: Number, default: 0 },
|
||||
totalPrice: { type: Number, default: 0 },
|
||||
department: {
|
||||
type: String, ref: 'Department',
|
||||
},
|
||||
items: [
|
||||
{
|
||||
order:
|
||||
{type: Schema.Types.ObjectId, ref: 'Order'},
|
||||
{ type: Schema.Types.ObjectId, ref: 'Order' },
|
||||
},
|
||||
],
|
||||
note: {
|
||||
@@ -31,57 +31,61 @@ const CartSchema = new Schema({
|
||||
|
||||
var Cart = module.exports = mongoose.model('Cart', CartSchema);
|
||||
|
||||
module.exports.findAllIdApp = async function(idapp, userId) {
|
||||
const myfind = {idapp, userId};
|
||||
module.exports.findAllIdApp = async function (idapp, userId) {
|
||||
const myfind = { idapp, userId };
|
||||
|
||||
return await Cart.findOne(myfind).lean();
|
||||
};
|
||||
|
||||
module.exports.getCartByUserId = async function(uid, idapp) {
|
||||
let query = {userId: uid, idapp};
|
||||
const mycart = await Cart.findOne(query).lean();
|
||||
module.exports.getCartByUserId = async function (uid, idapp) {
|
||||
try {
|
||||
let query = { userId: uid, idapp };
|
||||
const mycart = await Cart.findOne(query).lean();
|
||||
|
||||
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();
|
||||
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].order = myord[0];
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('err', e);
|
||||
}
|
||||
const myord = await Order.getTotalOrderById(idorder);
|
||||
if (myord.length > 0) {
|
||||
mycart.items[idkey].order = myord[0];
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('err', e);
|
||||
}
|
||||
return mycart;
|
||||
}
|
||||
return mycart;
|
||||
return null;
|
||||
} catch (e) {
|
||||
console.log('getCartByUserId err', e);
|
||||
}
|
||||
return null;
|
||||
|
||||
};
|
||||
|
||||
module.exports.updateCartByUserId = function(userId, newCart, callback) {
|
||||
let query = {userId: userId};
|
||||
Cart.find(query, function(err, c) {
|
||||
module.exports.updateCartByUserId = function (userId, newCart, callback) {
|
||||
let query = { userId: userId };
|
||||
Cart.find(query, function (err, c) {
|
||||
if (err) throw err;
|
||||
|
||||
//exist cart in databse
|
||||
if (c.length > 0) {
|
||||
Cart.findOneAndUpdate(
|
||||
{userId: userId},
|
||||
{
|
||||
$set: {
|
||||
items: newCart.items,
|
||||
totalQty: newCart.totalQty,
|
||||
totalPrice: newCart.totalPrice,
|
||||
userId: userId,
|
||||
},
|
||||
{ userId: userId },
|
||||
{
|
||||
$set: {
|
||||
items: newCart.items,
|
||||
totalQty: newCart.totalQty,
|
||||
totalPrice: newCart.totalPrice,
|
||||
userId: userId,
|
||||
},
|
||||
{new: true},
|
||||
callback,
|
||||
},
|
||||
{ new: true },
|
||||
callback,
|
||||
);
|
||||
} else {
|
||||
//no cart in database
|
||||
@@ -90,7 +94,7 @@ module.exports.updateCartByUserId = function(userId, newCart, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.updateCartByCartId = async function(cartId, newCart) {
|
||||
module.exports.updateCartByCartId = async function (cartId, newCart) {
|
||||
// delete newCart._doc._id;
|
||||
const items = newCart.items;
|
||||
const totalQty = newCart.totalQty;
|
||||
@@ -98,14 +102,14 @@ module.exports.updateCartByCartId = async function(cartId, newCart) {
|
||||
|
||||
const modify_at = new Date();
|
||||
|
||||
return await Cart.findOneAndUpdate({_id: cartId}, {
|
||||
return await Cart.findOneAndUpdate({ _id: cartId }, {
|
||||
$set: {
|
||||
items,
|
||||
totalPrice,
|
||||
totalQty,
|
||||
modify_at,
|
||||
},
|
||||
}, {new: false}).lean().then((ris) => {
|
||||
}, { new: false }).lean().then((ris) => {
|
||||
return ris;
|
||||
}).catch(err => {
|
||||
console.log('err', err);
|
||||
@@ -114,11 +118,11 @@ module.exports.updateCartByCartId = async function(cartId, newCart) {
|
||||
|
||||
};
|
||||
|
||||
module.exports.deleteCartByCartId = async function(cartId) {
|
||||
return await Cart.remove({_id: cartId});
|
||||
module.exports.deleteCartByCartId = async function (cartId) {
|
||||
return await Cart.remove({ _id: cartId });
|
||||
};
|
||||
|
||||
module.exports.createCart = async function(newCart) {
|
||||
module.exports.createCart = async function (newCart) {
|
||||
return await newCart.save();
|
||||
};
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
|
||||
const mongoose = require('mongoose').set('debug', false)
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
@@ -11,20 +13,41 @@ mongoose.plugin(schema => {
|
||||
});
|
||||
|
||||
const CategorySchema = new Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
unique: true,
|
||||
index: true,
|
||||
lowercase: true
|
||||
}
|
||||
},
|
||||
img: {
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
|
||||
module.exports.getAllCategories = function (callback) {
|
||||
CategorySchema.statics.getAllCategories = function (callback) {
|
||||
Category.find(callback)
|
||||
}
|
||||
|
||||
module.exports.getCategoryById = function (id, callback) {
|
||||
CategorySchema.statics.getCategoryById = function (id, callback) {
|
||||
Category.findById(id, callback);
|
||||
}
|
||||
|
||||
module.exports = mongoose.model('Category', CategorySchema);
|
||||
CategorySchema.statics.getFieldsForSearch = function () {
|
||||
return [{ field: 'name', type: tools.FieldType.string }]
|
||||
};
|
||||
|
||||
CategorySchema.statics.executeQueryTable = function (idapp, params) {
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
CategorySchema.statics.findAllIdApp = async function (idapp) {
|
||||
const myfind = { idapp };
|
||||
|
||||
return await Category.find(myfind);
|
||||
};
|
||||
|
||||
const Category = mongoose.model('Category', CategorySchema);
|
||||
|
||||
module.exports = { Category };
|
||||
|
||||
@@ -51,6 +51,9 @@ const orderSchema = new Schema({
|
||||
weight: {
|
||||
type: Number
|
||||
},
|
||||
unit: {
|
||||
type: Number
|
||||
},
|
||||
stars: {
|
||||
type: Number
|
||||
},
|
||||
|
||||
@@ -27,7 +27,6 @@ const productSchema = new Schema({
|
||||
],
|
||||
code: {
|
||||
type: String,
|
||||
lowercase: true
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
@@ -39,8 +38,13 @@ const productSchema = new Schema({
|
||||
type: String, ref: 'Department'
|
||||
},
|
||||
category: {
|
||||
type: String, ref: 'Category'
|
||||
// type: String
|
||||
type: Array,
|
||||
},
|
||||
prezzo_ivato: { // Con IVA
|
||||
type: Number
|
||||
},
|
||||
perc_iva: { // 4, 10, 22 &
|
||||
type: Number
|
||||
},
|
||||
price: {
|
||||
type: Number
|
||||
@@ -57,6 +61,9 @@ const productSchema = new Schema({
|
||||
weight: {
|
||||
type: Number
|
||||
},
|
||||
unit: {
|
||||
type: Number
|
||||
},
|
||||
quantityAvailable: {
|
||||
type: Number
|
||||
},
|
||||
@@ -183,6 +190,9 @@ module.exports.getProductByID = function (id, callback) {
|
||||
Product.findById(id, callback);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// const Product = mongoose.model('Product', ProductSchema);
|
||||
|
||||
// module.exports = { Product };
|
||||
// PROVA
|
||||
|
||||
@@ -1011,7 +1011,6 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
|
||||
arrcircuits.push(await City.getCircuitNameBystrProv(prov));
|
||||
}
|
||||
|
||||
|
||||
if (myrecnotifpass.tablerec === shared_consts.TABLES_MYGOODS) {
|
||||
idSector = myrectableorig.idSectorGood;
|
||||
} else {
|
||||
|
||||
@@ -4,6 +4,7 @@ const validator = require('validator');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const _ = require('lodash');
|
||||
|
||||
const printf = require('util').format;
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const { Settings } = require('../models/settings');
|
||||
@@ -2057,22 +2058,56 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
|
||||
req = tools.getReqByPar(idapp, usernameOrig);
|
||||
}
|
||||
|
||||
let userDest = null;
|
||||
if (usernameDest)
|
||||
userDest = await User.getUserShortDataByUsername(idapp, usernameDest);
|
||||
|
||||
const username_action = req.user.username;
|
||||
let username_worked = usernameDest;
|
||||
|
||||
let ris = null;
|
||||
let lang = '';
|
||||
let user = null;
|
||||
if (usernameOrig) {
|
||||
user = await User.getUserShortDataByUsername(idapp, usernameOrig);
|
||||
}
|
||||
lang = user ? user.lang : '';
|
||||
let update = {};
|
||||
try {
|
||||
if (cmd === shared_consts.FRIENDSCMD.SETTRUST) {
|
||||
|
||||
// Aggiungi alle amicizie
|
||||
await this.setFriendsCmd(req, idapp, usernameOrig, usernameDest,
|
||||
shared_consts.FRIENDSCMD.SETFRIEND, value);
|
||||
|
||||
return await User.updateOne({ idapp, username: usernameDest },
|
||||
let msgOrig = '';
|
||||
let msgDest = '';
|
||||
// Aggiorna true se lo accetti e false se non lo accetti
|
||||
const ris = await User.updateOne({ idapp, username: usernameDest },
|
||||
{ $set: { verified_by_aportador: value, trust_modified: new Date() } },
|
||||
{ new: false });
|
||||
|
||||
if (value) {
|
||||
// Aggiungi alle amicizie
|
||||
await this.setFriendsCmd(req, idapp, usernameOrig, usernameDest,
|
||||
shared_consts.FRIENDSCMD.SETFRIEND, value);
|
||||
|
||||
msgOrig = i18n.__({ phrase: '✅ Hai Abilitato l\'accesso alla App a %s !', locale: userDest.lang }, userDest.username);
|
||||
msgDest = i18n.__({ phrase: '✅ Sei stato Abilitato correttamente da %s!', locale: lang }, usernameOrig);
|
||||
msgAdmin = i18n.__({ phrase: '✅ %s è stato Abilitato correttamente (da %s)!', locale: userDest.lang }, userDest.username, usernameOrig);
|
||||
} else {
|
||||
msgOrig = i18n.__({ phrase: '🚫 Hai rifiutato l\'accesso alla App di RISO da parte di %s!', locale: userDest.lang }, userDest.username);
|
||||
msgDest = i18n.__({ phrase: '🚫 Ti è stato rifiutato l\'accesso. Probabilmente l\'username con cui ti sei registrato non ti conosce. (%s) !<br>Contatta l\'Assistenza Tecnica.', locale: lang }, usernameOrig);
|
||||
msgAdmin = i18n.__({ phrase: '🚫 %s ha rifiutato l\'accesso alla App a %s !', locale: userDest.lang }, usernameOrig, userDest.username);
|
||||
|
||||
}
|
||||
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameOrig, msgOrig);
|
||||
await telegrambot.sendMsgTelegram(idapp, userDest.username, msgDest);
|
||||
|
||||
// Invia questo msg anche all'Admin
|
||||
await telegrambot.sendMsgTelegramToTheAdmin(idapp, msgAdmin, true);
|
||||
|
||||
// telegrambot.askConfirmationUser(user.idapp, shared_consts.CallFunz.REGISTRATION, user, '', '', '', '');
|
||||
|
||||
return ris;
|
||||
|
||||
} else if (cmd === shared_consts.FRIENDSCMD.SETFRIEND) {
|
||||
// Aggiungo l'Amicizia a me
|
||||
const foundIfAlreadyFriend = await User.findOne({
|
||||
@@ -2378,7 +2413,7 @@ UserSchema.statics.sendCmd = async function (req, idapp, usernameOrig, usernameD
|
||||
let title = tools.getNomeAppByIdApp(idapp);
|
||||
let keyb = null;
|
||||
let descr = '';
|
||||
|
||||
|
||||
let send_notif = false;
|
||||
let send_msgTelegramBot = false;
|
||||
let actions = [];
|
||||
@@ -2395,7 +2430,7 @@ UserSchema.statics.sendCmd = async function (req, idapp, usernameOrig, usernameD
|
||||
openUrl = '/circuit/ris_italia';
|
||||
bottone = i18n.__({ phrase: 'CIRCUIT_OPEN_RISITALIA', locale: langdest });
|
||||
tag = 'risitalia';
|
||||
|
||||
|
||||
send_notif = true;
|
||||
send_msgTelegramBot = true;
|
||||
|
||||
@@ -2418,15 +2453,15 @@ UserSchema.statics.sendCmd = async function (req, idapp, usernameOrig, usernameD
|
||||
}
|
||||
|
||||
// Invia Msg
|
||||
if (send_msgTelegramBot && msgtelegram) {
|
||||
if (send_msgTelegramBot && msgtelegram) {
|
||||
await telegrambot.local_sendMsgTelegramByIdTelegram(idapp, telegid, msgtelegram, undefined, undefined, true, keyb);
|
||||
}
|
||||
|
||||
const userprofile = await User.getInfoFriendByUsername(idapp, usernameDest);
|
||||
const myuser = await User.getInfoFriendByUsername(idapp, usernameOrig);
|
||||
|
||||
|
||||
ris = { userprofile, myuser, popupOnApp, result: true };
|
||||
|
||||
|
||||
} catch (e) {
|
||||
popupOnApp = e;
|
||||
ris = { popupOnApp };
|
||||
@@ -3125,6 +3160,20 @@ UserSchema.statics.getAskedFriendsByUsername = async function (idapp, username)
|
||||
};
|
||||
|
||||
|
||||
UserSchema.statics.getUsersToVerify = async function (idapp, username) {
|
||||
|
||||
const whatToShow_Unknown = getWhatToShow(idapp, username);
|
||||
let usersToVerify = await User.find({
|
||||
idapp, aportador_solidario: username,
|
||||
verified_by_aportador: { $exists: false },
|
||||
$or: [
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}, whatToShow_Unknown).lean();
|
||||
|
||||
return usersToVerify;
|
||||
};
|
||||
|
||||
UserSchema.statics.getFriendsByUsername = async function (idapp, username) {
|
||||
|
||||
if (!username) {
|
||||
@@ -4076,7 +4125,7 @@ UserSchema.statics.getUsersDreams = async function (idapp) {
|
||||
UserSchema.statics.getLastUsers = async function (idapp) {
|
||||
const User = this;
|
||||
|
||||
const lastn = await Settings.getValDbSettings(idapp, 'SHOW_LAST_N_USERS', 10);
|
||||
const lastn = await Settings.getValDbSettings(idapp, 'SHOW_LAST_N_USERS', 20);
|
||||
|
||||
return await User.find(
|
||||
{
|
||||
@@ -4090,6 +4139,7 @@ UserSchema.statics.getLastUsers = async function (idapp) {
|
||||
name: 1,
|
||||
surname: 1,
|
||||
lasttimeonline: 1,
|
||||
verified_by_aportador: 1,
|
||||
'profile.img': 1,
|
||||
date_reg: 1,
|
||||
index: 1,
|
||||
@@ -5024,6 +5074,8 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, v
|
||||
|
||||
recUser.profile.reaction = await Reaction.find({ idapp, username: recUser.username }).lean();
|
||||
|
||||
recUser.profile.userstoverify = await User.getUsersToVerify(idapp, recUser.username);
|
||||
|
||||
recUser.profile.manage_mygroups = listManageGroups
|
||||
? listManageGroups
|
||||
: [];
|
||||
|
||||
@@ -30,17 +30,20 @@ const Cart = require('../models/cart');
|
||||
const OrdersCart = require('../models/orderscart');
|
||||
|
||||
//GET cart
|
||||
router.get('/:userId', authenticate, function (req, res, next) {
|
||||
let userId = req.body.userId
|
||||
let idapp = req.body.idapp
|
||||
Cart.getCartByUserId(userId, idapp, function (err, cart) {
|
||||
if (err) return next(err)
|
||||
router.get('/:userId', authenticate, async function (req, res, next) {
|
||||
let userId = req.params.userId
|
||||
let idapp = req.user.idapp
|
||||
return await Cart.getCartByUserId(userId, idapp)
|
||||
.then((cart) => {
|
||||
if (cart)
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, cart });
|
||||
else
|
||||
return res.status(400).send(e);
|
||||
}).catch((err) => {
|
||||
console.error('Err', err);
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, cart: null });
|
||||
});
|
||||
|
||||
if (cart)
|
||||
res.send({ code: server_constants.RIS_CODE_OK, cart });
|
||||
else
|
||||
res.status(400).send(e);
|
||||
})
|
||||
})
|
||||
|
||||
//POST cart
|
||||
@@ -51,46 +54,54 @@ router.post('/:userId', authenticate, async function (req, res, next) {
|
||||
let subqty = req.body.subqty;
|
||||
let order = req.body.order;
|
||||
|
||||
const mycart = await Cart.getCartByUserId(userId, idapp);
|
||||
try {
|
||||
|
||||
// const myorder = Order.getOrderByID(order._id);
|
||||
if (!addqty && !subqty)
|
||||
order._id = await Order.createOrder(order);
|
||||
const mycart = await Cart.getCartByUserId(userId, idapp);
|
||||
|
||||
let cart = null;
|
||||
// no cart save empty cart to database then return response
|
||||
let myqty = 0;
|
||||
if (!mycart) {
|
||||
let oldCart = new CartClass(order)
|
||||
cart = await Cart.createCart(oldCart.generateModel());
|
||||
} else {
|
||||
let newCart = CartClass.constructByCart(mycart);
|
||||
if (addqty) {
|
||||
myqty = await newCart.addqty(order);
|
||||
} else if (subqty) {
|
||||
myqty = await newCart.subqty(order);
|
||||
// const myorder = Order.getOrderByID(order._id);
|
||||
if (!addqty && !subqty)
|
||||
order._id = await Order.createOrder(order);
|
||||
|
||||
let cart = null;
|
||||
// no cart save empty cart to database then return response
|
||||
let myqty = 0;
|
||||
if (!mycart) {
|
||||
let oldCart = new CartClass(order)
|
||||
cart = await Cart.createCart(oldCart.generateModel());
|
||||
} else {
|
||||
const ind = newCart.addItem(order);
|
||||
let newCart = CartClass.constructByCart(mycart);
|
||||
if (addqty) {
|
||||
myqty = await newCart.addqty(order);
|
||||
} else if (subqty) {
|
||||
myqty = await newCart.subqty(order);
|
||||
} else {
|
||||
const ind = newCart.addItem(order);
|
||||
}
|
||||
cart = await Cart.updateCartByCartId(mycart._id, newCart.generateModel());
|
||||
}
|
||||
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 });
|
||||
} else {
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, cart: null });
|
||||
if (cart) {
|
||||
const carttot = await Cart.getCartByUserId(userId, idapp);
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, cart: carttot, qty: myqty });
|
||||
} else {
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, cart: null });
|
||||
}
|
||||
|
||||
/*
|
||||
Cart.updateCartByUserId(
|
||||
userId,
|
||||
newCart,
|
||||
function (err, result) {
|
||||
if (err) return next(err)
|
||||
return res.status(200).json({ cart: result })
|
||||
})
|
||||
|
||||
*/
|
||||
|
||||
|
||||
} catch (e) {
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, cart: 0 });
|
||||
}
|
||||
|
||||
/*
|
||||
Cart.updateCartByUserId(
|
||||
userId,
|
||||
newCart,
|
||||
function (err, result) {
|
||||
if (err) return next(err)
|
||||
return res.status(200).json({ cart: result })
|
||||
})
|
||||
|
||||
*/
|
||||
})
|
||||
|
||||
router.delete('/:userId', authenticate, async function (req, res) {
|
||||
@@ -122,47 +133,56 @@ router.delete('/:userId', authenticate, async function (req, res) {
|
||||
|
||||
|
||||
//PUT cart
|
||||
router.put('/:userId', authenticate, function (req, res, next) {
|
||||
router.put('/:userId', authenticate, async function (req, res, next) {
|
||||
let userId = req.params.userId
|
||||
let requestProduct = req.body
|
||||
let { productId, color, size } = requestProduct.product
|
||||
|
||||
Cart.getCartByUserId(userId, function (err, c) {
|
||||
if (err) return next(err)
|
||||
let oldCart = new CartClass(c[0] || {})
|
||||
Product.getProductByID(productId, function (err, p) {
|
||||
if (err) return next(err)
|
||||
let newCart = oldCart.add(p, productId, { color, size })
|
||||
try {
|
||||
|
||||
//exist cart in databse
|
||||
if (c.length > 0) {
|
||||
Cart.updateCartByUserId(
|
||||
userId,
|
||||
{
|
||||
await Cart.getCartByUserId(userId, function (err, c) {
|
||||
if (err) return next(err)
|
||||
let oldCart = new CartClass(c[0] || {})
|
||||
|
||||
Product.getProductByID(productId, 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(
|
||||
userId,
|
||||
{
|
||||
items: newCart.items,
|
||||
totalQty: newCart.totalQty,
|
||||
totalPrice: newCart.totalPrice,
|
||||
userId: userId
|
||||
},
|
||||
function (err, result) {
|
||||
if (err) return next(err)
|
||||
res.json(result)
|
||||
})
|
||||
} else {
|
||||
//no cart in database
|
||||
newCart = new Cart({
|
||||
items: newCart.items,
|
||||
totalQty: newCart.totalQty,
|
||||
totalPrice: newCart.totalPrice,
|
||||
userId: userId
|
||||
},
|
||||
function (err, result) {
|
||||
if (err) return next(err)
|
||||
res.json(result)
|
||||
})
|
||||
} else {
|
||||
//no cart in database
|
||||
newCart = new Cart({
|
||||
items: newCart.items,
|
||||
totalQty: newCart.totalQty,
|
||||
totalPrice: newCart.totalPrice,
|
||||
userId: userId
|
||||
})
|
||||
Cart.createCart(newCart, function (err, resultCart) {
|
||||
if (err) return next(err)
|
||||
res.status(201).json(resultCart)
|
||||
})
|
||||
}
|
||||
Cart.createCart(newCart, function (err, resultCart) {
|
||||
if (err) return next(err)
|
||||
res.status(201).json(resultCart)
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return res.send({ code: server_constants.RIS_CODE_OK });
|
||||
} catch (e) {
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, status: 0 });
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
//POST cart
|
||||
|
||||
@@ -66,6 +66,7 @@ const Cart = require('../models/cart');
|
||||
const OrdersCart = require('../models/orderscart');
|
||||
const Storehouse = require('../models/storehouse');
|
||||
const Department = require('../models/department');
|
||||
const { Category } = require('../models/category');
|
||||
const Group = require('../models/group');
|
||||
|
||||
const tools = require('../tools/general');
|
||||
@@ -373,6 +374,7 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
if ((mydata['_id'] === undefined || mydata['_id'] === '' || (mytablerec.isNew && mydata['_id'] === 0)) && (mytablerec._id === undefined || mytablerec._id === '0')) {
|
||||
mytablerec._id = new ObjectID();
|
||||
mydata._id = new ObjectID();
|
||||
mytablerec.isNew = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1403,6 +1405,7 @@ function load(req, res, version) {
|
||||
let workers = User.getusersWorkersList(idapp);
|
||||
let storehouses = Storehouse.findAllIdApp(idapp);
|
||||
let departments = Department.findAllIdApp(idapp);
|
||||
let categories = Category.findAllIdApp(idapp);
|
||||
|
||||
// SKILLS:
|
||||
let levels = Level.findAllIdApp(idapp);
|
||||
@@ -1486,6 +1489,7 @@ function load(req, res, version) {
|
||||
mygroups,
|
||||
listcircuits, // 37
|
||||
myelems, // 38
|
||||
categories, // 39
|
||||
]).then((arrdata) => {
|
||||
// console.table(arrdata);
|
||||
let myuser = req.user;
|
||||
@@ -1567,7 +1571,10 @@ function load(req, res, version) {
|
||||
mygroups: arrdata[36],
|
||||
listcircuits: arrdata[37],
|
||||
myelems: arrdata[38],
|
||||
categories: arrdata[39],
|
||||
});
|
||||
|
||||
const prova = 1;
|
||||
}
|
||||
|
||||
}).catch((e) => {
|
||||
|
||||
@@ -27,6 +27,8 @@ const shared_consts = require('./tools/shared_nodejs');
|
||||
|
||||
const {User} = require('./models/user');
|
||||
|
||||
const { MsgTemplate } = require('./models/msg_template');
|
||||
|
||||
const transport_preview = nodemailer.createTransport({
|
||||
jsonTransport: true,
|
||||
});
|
||||
@@ -168,6 +170,9 @@ module.exports = {
|
||||
|
||||
// console.log('idapp', idapp, tools.getNomeAppByIdApp(idapp));
|
||||
|
||||
// ++ estrai l'html da mettere sulla email:
|
||||
// const msghtml = await MsgTemplate.getMsgByLang(idapp, user, shared_consts.TypeMsgTemplate.MSG_BENV_REGISTRATO, user.lang);
|
||||
|
||||
let mylocalsconf = {
|
||||
idapp,
|
||||
dataemail: await this.getdataemail(idapp),
|
||||
|
||||
@@ -893,6 +893,8 @@ const MyTelegramBot = {
|
||||
}, */
|
||||
]);
|
||||
}
|
||||
send_notif = true;
|
||||
|
||||
} else if (myfunc === shared_consts.CallFunz.RICHIESTA_GRUPPO) {
|
||||
|
||||
domanda = printf(getstr(langdest, 'MSG_ACCEPT_NEWENTRY_INGROUP'), name) + '<br>' + struserinfomsg;
|
||||
@@ -924,6 +926,8 @@ const MyTelegramBot = {
|
||||
groupid + tools.SEP + groupname,
|
||||
},*/
|
||||
]);
|
||||
send_notif = true;
|
||||
|
||||
} else {
|
||||
domanda = i18n.__({ phrase: 'CIRCUIT_ACCEPT_NEWENTRY', locale: langdest }, myuser.username, name) + '<br>' + struserinfomsg;
|
||||
|
||||
@@ -939,6 +943,7 @@ const MyTelegramBot = {
|
||||
groupid,
|
||||
}, */
|
||||
]);
|
||||
send_notif = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ const Cart = require('../models/cart');
|
||||
const OrdersCart = require('../models/orderscart');
|
||||
const Storehouse = require('../models/storehouse');
|
||||
const Department = require('../models/department');
|
||||
const { Category } = require('../models/category');
|
||||
const ShareWithUs = require('../models/sharewithus');
|
||||
const Site = require('../models/site');
|
||||
const IscrittiConacreis = require('../models/iscrittiConacreis');
|
||||
@@ -105,6 +106,8 @@ module.exports = {
|
||||
mytable = Storehouse;
|
||||
else if (tablename === 'departments')
|
||||
mytable = Department;
|
||||
else if (tablename === 'categorys')
|
||||
mytable = Category;
|
||||
else if (tablename === 'sharewithus')
|
||||
mytable = ShareWithUs;
|
||||
else if (tablename === 'sites')
|
||||
|
||||
@@ -326,6 +326,38 @@ module.exports = {
|
||||
OPZ1_2: 2,
|
||||
},
|
||||
|
||||
UNITS_OF_MEASURE: {
|
||||
NESSUNO: 0,
|
||||
GRAMMI: 1,
|
||||
CHILI: 2,
|
||||
LITRI: 3,
|
||||
PEZZI: 4,
|
||||
},
|
||||
|
||||
Units_Of_Measure_ListBox: [
|
||||
{
|
||||
label: '[Nessuno]',
|
||||
value: 0,
|
||||
},
|
||||
{
|
||||
label: 'Grammi (g)',
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
label: 'Chili (kg)',
|
||||
value: 2,
|
||||
},
|
||||
{
|
||||
label: 'Litri (l)',
|
||||
value: 3,
|
||||
},
|
||||
{
|
||||
label: 'Pezzi (p)',
|
||||
value: 4,
|
||||
},
|
||||
],
|
||||
|
||||
|
||||
CallFunz: {
|
||||
SOSTITUISCI: 345,
|
||||
AGGIUNGI_NUOVO_IMBARCO: 380,
|
||||
@@ -379,6 +411,7 @@ module.exports = {
|
||||
TypeMsgTemplate: {
|
||||
MSG_BENVENUTO: 2010,
|
||||
MS_SHARE_LINK: 2000,
|
||||
MSG_BENV_REGISTRATO: 2020,
|
||||
},
|
||||
|
||||
TypeSend: {
|
||||
@@ -757,6 +790,7 @@ module.exports = {
|
||||
myreact: 1,
|
||||
mycities: 1,
|
||||
lang: 1,
|
||||
verified_by_aportador: 1,
|
||||
'profile.img': 1,
|
||||
'profile.mygroups': 1,
|
||||
'profile.mycircuits': 1,
|
||||
|
||||
Reference in New Issue
Block a user