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

@@ -157,6 +157,20 @@ module.exports.findAllIdApp = async function (idapp) {
as: 'provider'
}
},
{
$lookup: {
from: 'scontisticas',
localField: 'idScontisticas',
foreignField: '_id',
as: 'scontistica'
}
},
{
$unwind: {
path: '$scontistica',
preserveNullAndEmptyArrays: true,
},
},
{ $unwind: '$product' },
{ $unwind: '$producer' },
{ $unwind: '$provider' },
@@ -244,6 +258,20 @@ module.exports.getTotalOrderById = async function (id) {
as: 'provider'
}
},
{
$lookup: {
from: 'scontisticas',
localField: 'idScontisticas',
foreignField: '_id',
as: 'scontistica'
}
},
{
$unwind: {
path: '$scontistica',
preserveNullAndEmptyArrays: true,
},
},
{ $unwind: '$product' },
{ $unwind: '$producer' },
{ $unwind: '$storehouse' },

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',

View File

@@ -0,0 +1,59 @@
mongoose = require('mongoose').set('debug', false)
const Schema = mongoose.Schema;
const tools = require('../tools/general');
mongoose.Promise = global.Promise;
mongoose.level = "F";
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
const scontisticaSchema = new Schema({
idapp: {
type: String,
},
code: {
type: String,
},
description: {
type: String,
},
qta: {
type: Number,
},
perc_sconto: {
type: Number,
},
price: {
type: Number,
},
comulativo: {
type: Boolean,
default: false,
},
});
var Scontistica = module.exports = mongoose.model('Scontistica', scontisticaSchema);
module.exports.getFieldsForSearch = function () {
return [{ field: 'name', type: tools.FieldType.string }]
};
module.exports.executeQueryTable = function (idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, idapp, params);
};
module.exports.findAllIdApp = async function (idapp) {
const myfind = { idapp };
return await Scontistica.find(myfind);
};
module.exports.createIndexes((err) => {
if (err) throw err;
});