aggiornamento visualizzazione Ordini e Carrello
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
const mongoose = require('mongoose').set('debug', false);
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
});
|
||||
|
||||
const Order = require('../models/order');
|
||||
|
||||
const CartSchema = new Schema({
|
||||
idapp: {
|
||||
@@ -31,10 +36,6 @@ const CartSchema = new Schema({
|
||||
|
||||
var Cart = module.exports = mongoose.model('Cart', CartSchema);
|
||||
|
||||
Cart.createIndexes((err) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
|
||||
module.exports.findAllIdApp = async function (idapp, userId) {
|
||||
const myfind = { idapp, userId };
|
||||
|
||||
@@ -43,6 +44,8 @@ module.exports.findAllIdApp = async function (idapp, userId) {
|
||||
|
||||
module.exports.getCartByUserId = async function (uid, idapp) {
|
||||
try {
|
||||
const Order = require('../models/order');
|
||||
|
||||
let query = { userId: uid, idapp };
|
||||
const mycart = await Cart.findOne(query).lean();
|
||||
|
||||
@@ -130,3 +133,7 @@ module.exports.createCart = async function (newCart) {
|
||||
return await newCart.save();
|
||||
};
|
||||
|
||||
|
||||
Cart.createIndexes((err) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
|
||||
@@ -43,12 +43,16 @@ const OrdersCartSchema = new Schema({
|
||||
completed_at: {
|
||||
type: Date
|
||||
},
|
||||
deleted: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
});
|
||||
|
||||
var OrdersCart = module.exports = mongoose.model('OrdersCart', OrdersCartSchema);
|
||||
|
||||
module.exports.findAllIdApp = async function (idapp, userId) {
|
||||
const myfind = { idapp, userId };
|
||||
const myfind = { idapp, userId, deleted: false };
|
||||
|
||||
return await await OrdersCart.find(myfind);
|
||||
};
|
||||
@@ -64,7 +68,7 @@ module.exports.getFieldsForSearch = function () {
|
||||
|
||||
|
||||
module.exports.getNewNumOrder = async function (uid, idapp) {
|
||||
let query = { userId: uid, idapp }
|
||||
let query = { userId: uid, idapp, deleted: false }
|
||||
let numorder = 1;
|
||||
let numorderrec = await OrdersCart.find(query).sort({ numorder: -1 }).limit(1);
|
||||
if (numorderrec.length <= 0)
|
||||
@@ -99,7 +103,7 @@ module.exports.getStatusCartByUserId = async function (uid, idapp, numorder) {
|
||||
}
|
||||
module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder) {
|
||||
|
||||
let query = { idapp, status: { $gte: shared_consts.OrderStatus.CHECKOUT_SENT } }
|
||||
let query = { idapp, status: { $gte: shared_consts.OrderStatus.CHECKOUT_SENT }, deleted: false }
|
||||
let myorderscart = null;
|
||||
if (numorder > 0) {
|
||||
query.numorder = numorder;
|
||||
@@ -153,7 +157,10 @@ module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder) {
|
||||
}
|
||||
|
||||
module.exports.getOrdersCartByDepartmentId = async function (depId, idapp) {
|
||||
let query = { idapp, status: { $gte: shared_consts.OrderStatus.CHECKOUT_SENT } }
|
||||
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++) {
|
||||
@@ -207,7 +214,10 @@ module.exports.getOrderById = async function (Id, idapp) {
|
||||
}
|
||||
|
||||
module.exports.updateOrdersCartById = function (id, newOrdersCart, callback) {
|
||||
let query = { id: id }
|
||||
let query = {
|
||||
id,
|
||||
deleted: false,
|
||||
}
|
||||
OrdersCart.find(query, function (err, c) {
|
||||
if (err) throw err
|
||||
|
||||
|
||||
@@ -53,7 +53,8 @@ const productSchema = new Schema({
|
||||
type: Number
|
||||
},
|
||||
price: {
|
||||
type: Number
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
after_price: {
|
||||
type: String
|
||||
@@ -74,7 +75,8 @@ const productSchema = new Schema({
|
||||
type: Number
|
||||
},
|
||||
stockQty: { // in magazzino
|
||||
type: Number
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
quantityAvailable: {
|
||||
type: Number
|
||||
|
||||
Reference in New Issue
Block a user