subcatprod
This commit is contained in:
@@ -7,6 +7,7 @@ const Producer = require('../models/producer');
|
||||
const Storehouse = require('../models/storehouse');
|
||||
const Provider = require('../models/provider');
|
||||
const CatProd = require('../models/catprod');
|
||||
const SubCatProd = require('../models/subcatprod');
|
||||
const Gasordine = require('../models/gasordine');
|
||||
const Scontistica = require('../models/scontistica');
|
||||
|
||||
@@ -153,6 +154,9 @@ const productSchema = new Schema({
|
||||
cat_name: {
|
||||
type: String,
|
||||
},
|
||||
subcat_name: {
|
||||
type: String,
|
||||
},
|
||||
sconto1: {
|
||||
type: String,
|
||||
},
|
||||
@@ -318,6 +322,14 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
|
||||
as: 'catprods'
|
||||
}
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'subcatprods',
|
||||
localField: 'idSubCatProds',
|
||||
foreignField: '_id',
|
||||
as: 'subcatprods'
|
||||
}
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'scontisticas',
|
||||
@@ -696,6 +708,7 @@ module.exports.singlerecconvert_AfterImport_AndSave = async function (idapp, pro
|
||||
|
||||
const objDelete = {
|
||||
cat_name: 1,
|
||||
subcat_name: 1,
|
||||
producer_name: 1,
|
||||
provider_name: 1,
|
||||
magazzino_name: 1,
|
||||
|
||||
@@ -37,6 +37,7 @@ const productInfoSchema = new Schema({
|
||||
type: String,
|
||||
},
|
||||
idCatProds: [{ type: Schema.Types.ObjectId, ref: 'CatProd' }],
|
||||
idSubCatProds: [{ type: Schema.Types.ObjectId, ref: 'SubCatProd' }],
|
||||
color: {
|
||||
type: String
|
||||
},
|
||||
@@ -131,6 +132,14 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
|
||||
as: 'catprods'
|
||||
}
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'subcatprods',
|
||||
localField: 'idSubCatProds',
|
||||
foreignField: '_id',
|
||||
as: 'subcatprods'
|
||||
}
|
||||
},
|
||||
{
|
||||
$sort: {
|
||||
name: 1 // 1 for ascending order, -1 for descending order
|
||||
|
||||
65
src/server/models/subcatprod.js
Executable file
65
src/server/models/subcatprod.js
Executable file
@@ -0,0 +1,65 @@
|
||||
|
||||
const mongoose = require('mongoose').set('debug', false)
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
});
|
||||
|
||||
const SubCatProdSchema = new Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
},
|
||||
idCatProd: {
|
||||
type: String,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
},
|
||||
img: {
|
||||
type: String,
|
||||
},
|
||||
icon: {
|
||||
type: String,
|
||||
},
|
||||
color: {
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
|
||||
SubCatProdSchema.statics.getAllCategories = function (callback) {
|
||||
SubCatProd.find(callback)
|
||||
}
|
||||
|
||||
SubCatProdSchema.statics.getSubCatProdById = function (id, callback) {
|
||||
SubCatProd.findById(id, callback);
|
||||
}
|
||||
|
||||
SubCatProdSchema.statics.getFieldsForSearch = function () {
|
||||
return [{ field: 'name', type: tools.FieldType.string }]
|
||||
};
|
||||
|
||||
SubCatProdSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
SubCatProdSchema.statics.findAllIdApp = async function (idapp) {
|
||||
const myfind = { idapp };
|
||||
|
||||
return await SubCatProd.find(myfind).sort({ name: 1 });
|
||||
};
|
||||
|
||||
const SubCatProd = mongoose.model('SubCatProd', SubCatProdSchema);
|
||||
|
||||
SubCatProd.createIndexes((err) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
|
||||
|
||||
module.exports = SubCatProd;
|
||||
Reference in New Issue
Block a user