Scontistica- Parte 1
This commit is contained in:
@@ -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' },
|
||||
|
||||
@@ -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',
|
||||
|
||||
59
src/server/models/scontistica.js
Executable file
59
src/server/models/scontistica.js
Executable 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;
|
||||
});
|
||||
Reference in New Issue
Block a user