Scontistica- Parte 1

This commit is contained in:
Surya Paolo
2023-12-16 00:51:03 +01:00
parent 1ca72118f1
commit ab3a31d4fb
7 changed files with 127 additions and 4 deletions

View File

@@ -6,6 +6,7 @@ const tools = require('../tools/general');
const Producer = require('../models/producer');
const Storehouse = require('../models/storehouse');
const Provider = require('../models/provider');
const Scontistica = require('../models/scontistica');
const shared_consts = require('../tools/shared_nodejs');
@@ -33,6 +34,9 @@ const productSchema = new Schema({
idStorehouses: [
{ type: Schema.Types.ObjectId, ref: 'Storehouse' }
],
idScontisticas: [
{ type: Schema.Types.ObjectId, ref: 'Scontistica' }
],
idProvider: { type: Schema.Types.ObjectId, ref: 'Provider' },
code: {
type: String,
@@ -214,7 +218,12 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
as: 'producer'
}
},
{ $unwind: '$producer' },
{
$unwind: {
path: '$producer',
preserveNullAndEmptyArrays: true,
},
},
{
$lookup: {
from: 'providers',
@@ -223,7 +232,26 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
as: 'provider'
}
},
{ $unwind: '$provider' },
{
$unwind: {
path: '$provider',
preserveNullAndEmptyArrays: true,
},
},
{
$lookup: {
from: 'scontisticas',
localField: 'idScontisticas',
foreignField: '_id',
as: 'scontistica'
}
},
{
$unwind: {
path: '$scontistica',
preserveNullAndEmptyArrays: true,
},
},
{
$lookup: {
from: 'storehouses',