Develop PDB 1
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
|
||||
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 => {
|
||||
@@ -11,20 +13,41 @@ mongoose.plugin(schema => {
|
||||
});
|
||||
|
||||
const CategorySchema = new Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
unique: true,
|
||||
index: true,
|
||||
lowercase: true
|
||||
}
|
||||
},
|
||||
img: {
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
|
||||
module.exports.getAllCategories = function (callback) {
|
||||
CategorySchema.statics.getAllCategories = function (callback) {
|
||||
Category.find(callback)
|
||||
}
|
||||
|
||||
module.exports.getCategoryById = function (id, callback) {
|
||||
CategorySchema.statics.getCategoryById = function (id, callback) {
|
||||
Category.findById(id, callback);
|
||||
}
|
||||
|
||||
module.exports = mongoose.model('Category', CategorySchema);
|
||||
CategorySchema.statics.getFieldsForSearch = function () {
|
||||
return [{ field: 'name', type: tools.FieldType.string }]
|
||||
};
|
||||
|
||||
CategorySchema.statics.executeQueryTable = function (idapp, params) {
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
CategorySchema.statics.findAllIdApp = async function (idapp) {
|
||||
const myfind = { idapp };
|
||||
|
||||
return await Category.find(myfind);
|
||||
};
|
||||
|
||||
const Category = mongoose.model('Category', CategorySchema);
|
||||
|
||||
module.exports = { Category };
|
||||
|
||||
@@ -27,7 +27,6 @@ const productSchema = new Schema({
|
||||
],
|
||||
code: {
|
||||
type: String,
|
||||
lowercase: true
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
@@ -39,8 +38,13 @@ const productSchema = new Schema({
|
||||
type: String, ref: 'Department'
|
||||
},
|
||||
category: {
|
||||
type: String, ref: 'Category'
|
||||
// type: String
|
||||
type: Array,
|
||||
},
|
||||
prezzo_ivato: {
|
||||
type: Number
|
||||
},
|
||||
perc_iva: { // 4, 10, 22 &
|
||||
type: Number
|
||||
},
|
||||
price: {
|
||||
type: Number
|
||||
|
||||
Reference in New Issue
Block a user