mongoose = require('mongoose'); 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 productSchema = new Schema({ idapp: { type: String, }, idProducer: { type: String }, name: { type: String, }, description: { type: String, }, department: { type: String }, category: { type: mongoose.Schema.Types.ObjectId, ref: 'Category' // type: String }, price: { type: Number }, color: { type: String }, size: { type: String }, quantity: { type: Number }, date: { type: Number }, icon: { type: String, }, img: { type: String, }, }); var Product = module.exports = mongoose.model('Product', productSchema); 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 Product.find(myfind); }; module.exports.getAllProducts = function (query, sort, callback) { Product.find(query, null, sort, callback) } module.exports.getProductByDepartment = function (query,sort, callback) { Product.find(query, null, sort, callback) } module.exports.getProductByCategory = function (query,sort, callback) { Product.find(query, null, sort, callback) } module.exports.getProductByTitle = function (query,sort, callback) { Product.find(query, null, sort, callback) } module.exports.filterProductByDepartment = function (department, callback) { let regexp = new RegExp(`${department}`, 'i') var query = { department: { $regex: regexp } }; Product.find(query, callback) } module.exports.filterProductByCategory = function (category, callback) { let regexp = new RegExp(`${category}`, 'i') var query = { category: { $regex: regexp } }; Product.find(query, callback); } module.exports.filterProductByTitle = function (title, callback) { let regexp = new RegExp(`${title}`, 'i') var query = { title: { $regex: regexp } }; Product.find(query, callback); } module.exports.getProductByID = function (id, callback) { Product.findById(id, callback); } // const Product = mongoose.model('Product', ProductSchema); // module.exports = { Product };