Project e Todos sistemati...
aggiunti Gruppi
This commit is contained in:
@@ -5,6 +5,8 @@ const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const Order = require('../models/order');
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
const OrdersCartSchema = new Schema({
|
||||
@@ -15,6 +17,9 @@ const OrdersCartSchema = new Schema({
|
||||
userId: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||
totalQty: { type: Number, default: 0 },
|
||||
totalPrice: { type: Number, default: 0 },
|
||||
department: {
|
||||
type: String, ref: 'Department'
|
||||
},
|
||||
items: [
|
||||
{
|
||||
order:
|
||||
@@ -22,7 +27,8 @@ const OrdersCartSchema = new Schema({
|
||||
}
|
||||
],
|
||||
status: {
|
||||
type: Number
|
||||
type: Number,
|
||||
Default: 0,
|
||||
},
|
||||
note: {
|
||||
type: String
|
||||
@@ -40,7 +46,16 @@ var OrdersCart = module.exports = mongoose.model('OrdersCart', OrdersCartSchema)
|
||||
module.exports.findAllIdApp = async function (idapp, userId) {
|
||||
const myfind = { idapp, userId };
|
||||
|
||||
return await OrdersCart.findOne(myfind);
|
||||
return await OrdersCart.find(myfind);
|
||||
};
|
||||
|
||||
module.exports.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
module.exports.getFieldsForSearch = function () {
|
||||
return [{field: 'note', type: tools.FieldType.string}]
|
||||
};
|
||||
|
||||
|
||||
@@ -64,7 +79,7 @@ module.exports.getNewNumOrder = async function (uid, idapp) {
|
||||
};
|
||||
|
||||
module.exports.getOrdersCartByUserId = async function (uid, idapp) {
|
||||
let query = { userId: uid, idapp, status: { $gte: shared_consts.OrderStatus.CHECKOUT_CONFIRMED } }
|
||||
let query = { userId: uid, idapp, status: { $gte: shared_consts.OrderStatus.CHECKOUT_SENT } }
|
||||
const myorderscart = await OrdersCart.find(query);
|
||||
|
||||
for (let ind = 0; ind < myorderscart.length; ind++) {
|
||||
@@ -107,6 +122,32 @@ module.exports.getOrdersCartByUserId = async function (uid, idapp) {
|
||||
// return null;
|
||||
}
|
||||
|
||||
module.exports.getOrdersCartByDepartmentId = async function (depId, idapp) {
|
||||
let query = { idapp, status: { $gte: shared_consts.OrderStatus.CHECKOUT_SENT } }
|
||||
const myorderscart = await OrdersCart.find(query);
|
||||
|
||||
for (let ind = 0; ind < myorderscart.length; ind++) {
|
||||
for (const idkey in myorderscart[ind].items) {
|
||||
try {
|
||||
idorder = myorderscart[ind].items[idkey]._id.toString();
|
||||
const myorder = myorderscart[ind].items[idkey].order;
|
||||
if (!!myorder) {
|
||||
idorder = myorderscart[ind].items[idkey].order._id.toString();
|
||||
}
|
||||
const myord = await Order.getTotalOrderById(idorder);
|
||||
if (myord.length > 0) {
|
||||
myorderscart[ind].items[idkey]._doc.order = myord[0];
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('err', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return myorderscart
|
||||
// return null;
|
||||
}
|
||||
|
||||
module.exports.updateOrdersCartById = function (id, newOrdersCart, callback) {
|
||||
let query = { id: id }
|
||||
OrdersCart.find(query, function (err, c) {
|
||||
|
||||
Reference in New Issue
Block a user