aggiornamento scontistica, corretto errori

This commit is contained in:
Surya Paolo
2023-12-16 18:40:17 +01:00
parent ab3a31d4fb
commit 4290895a97
11 changed files with 132 additions and 44 deletions

View File

@@ -25,6 +25,7 @@ const orderSchema = new Schema({
idProduct: { type: Schema.Types.ObjectId, ref: 'Product' },
idProducer: { type: Schema.Types.ObjectId, ref: 'Producer' },
idStorehouse: { type: Schema.Types.ObjectId, ref: 'StoreHouse' },
idScontisticas: [{ type: Schema.Types.ObjectId, ref: 'Scontistica' }],
idProvider: { type: Schema.Types.ObjectId, ref: 'Provider' },
price: {
type: Number
@@ -167,13 +168,23 @@ module.exports.findAllIdApp = async function (idapp) {
},
{
$unwind: {
path: '$scontistica',
path: '$product',
preserveNullAndEmptyArrays: true,
},
},
{ $unwind: '$product' },
{ $unwind: '$producer' },
{ $unwind: '$provider' },
{
$unwind: {
path: '$producer',
preserveNullAndEmptyArrays: true,
},
},
{
$unwind: {
path: '$provider',
preserveNullAndEmptyArrays: true,
},
}
];
return await Order.aggregate(query)
@@ -263,19 +274,33 @@ module.exports.getTotalOrderById = async function (id) {
from: 'scontisticas',
localField: 'idScontisticas',
foreignField: '_id',
as: 'scontistica'
as: 'scontisticas'
}
},
{
$unwind: {
path: '$scontistica',
path: '$product',
preserveNullAndEmptyArrays: true,
},
},
{ $unwind: '$product' },
{ $unwind: '$producer' },
{ $unwind: '$storehouse' },
{ $unwind: '$provider' },
{
$unwind: {
path: '$producer',
preserveNullAndEmptyArrays: true,
},
},
{
$unwind: {
path: '$storehouse',
preserveNullAndEmptyArrays: true,
},
},
{
$unwind: {
path: '$provider',
preserveNullAndEmptyArrays: true,
},
}
];
return await Order.aggregate(query);