Aggiunto messaggio nella registrazione, dicendo che occorre avere Telegram installato.

PASSARE TUTTI I _DOC e mettergli .lean() prima dello then()  -> velocizza le Query di Mongodb
"Floriterapia
costellazioni familiari
coach motivazionale
Tecniche Essene"
Inserimento Gruppi: anche il comune obbligatorio
Far comparire le ultime persone registrate
Mettere il controllo dell'abilitazione del BOT Telegram solo dopo che conosco il suo username, e cosi gli metto anche il contatto telegram.
risolto foto profilo di telegram che non si salvava in automatico
tolto il controllo della email
aggiunto msg se errore al server, installare altro browser.
This commit is contained in:
paoloar77
2022-03-03 20:32:04 +01:00
parent 94a2a073e5
commit c1cecc5eb4
11 changed files with 228 additions and 169 deletions

View File

@@ -1,5 +1,4 @@
const mongoose = require('mongoose').set('debug', false)
const mongoose = require('mongoose').set('debug', false);
const Schema = mongoose.Schema;
const shared_consts = require('../tools/shared_nodejs');
@@ -8,40 +7,39 @@ const Order = require('../models/order');
const CartSchema = new Schema({
idapp: {
type: String
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'
type: String, ref: 'Department',
},
items: [
{
order:
{ type: Schema.Types.ObjectId, ref: 'Order' }
}
{type: Schema.Types.ObjectId, ref: 'Order'},
},
],
note: {
type: String
type: String,
},
modify_at: {
type: Date
type: Date,
},
});
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);
return await Cart.findOne(myfind).lean();
};
module.exports.getCartByUserId = async function (uid, idapp) {
let query = { userId: uid, idapp }
const mycart = await Cart.findOne(query);
module.exports.getCartByUserId = async function(uid, idapp) {
let query = {userId: uid, idapp};
const mycart = await Cart.findOne(query).lean();
if (!!mycart) {
for (const idkey in mycart.items) {
@@ -53,7 +51,7 @@ module.exports.getCartByUserId = async function (uid, idapp) {
}
const myord = await Order.getTotalOrderById(idorder);
if (myord.length > 0) {
mycart.items[idkey]._doc.order = myord[0];
mycart.items[idkey].order = myord[0];
}
} catch (e) {
console.log('err', e);
@@ -63,66 +61,64 @@ module.exports.getCartByUserId = async function (uid, idapp) {
}
return null;
}
};
module.exports.updateCartByUserId = function (userId, newCart, callback) {
let query = { userId: userId }
Cart.find(query, function (err, c) {
if (err) throw err
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
}
},
{ new: true },
callback
)
{userId: userId},
{
$set: {
items: newCart.items,
totalQty: newCart.totalQty,
totalPrice: newCart.totalPrice,
userId: userId,
},
},
{new: true},
callback,
);
} else {
//no cart in database
newCart.save(callback)
newCart.save(callback);
}
})
}
});
};
module.exports.updateCartByCartId = async function (cartId, newCart) {
module.exports.updateCartByCartId = async function(cartId, newCart) {
// delete newCart._doc._id;
const items = newCart._doc.items;
const items = newCart.items;
const totalQty = newCart.totalQty;
const totalPrice = newCart.totalPrice;
const modify_at = new Date();
return await Cart.findOneAndUpdate({ _id: cartId }, {
return Cart.findOneAndUpdate({_id: cartId}, {
$set: {
items,
totalPrice,
totalQty,
modify_at
}
}, { new: false })
.then((ris) => {
return ris;
}).catch(err => {
console.log('err', err);
return null
})
modify_at,
},
}, {new: false}).lean().then((ris) => {
return ris;
}).catch(err => {
console.log('err', err);
return null;
});
}
};
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) {
return await newCart.save()
}
module.exports.createCart = async function(newCart) {
return await newCart.save();
};