Ordini
This commit is contained in:
@@ -22,6 +22,10 @@ const productSchema = new Schema({
|
||||
idStorehouses: [
|
||||
{ type: Schema.Types.ObjectId, ref: 'Storehouse' }
|
||||
],
|
||||
code: {
|
||||
type: String,
|
||||
lowercase: true
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
},
|
||||
@@ -50,6 +54,12 @@ const productSchema = new Schema({
|
||||
quantityAvailable: {
|
||||
type: Number
|
||||
},
|
||||
canBeShipped: { // è spedibile
|
||||
type: Boolean
|
||||
},
|
||||
canBeBuyOnline: { // è acquistabile online
|
||||
type: Boolean
|
||||
},
|
||||
stars: {
|
||||
type: Number
|
||||
},
|
||||
@@ -62,6 +72,12 @@ const productSchema = new Schema({
|
||||
img: {
|
||||
type: String,
|
||||
},
|
||||
img2: {
|
||||
type: String,
|
||||
},
|
||||
img3: {
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
|
||||
var Product = module.exports = mongoose.model('Product', productSchema);
|
||||
@@ -75,13 +91,17 @@ module.exports.executeQueryTable = function (idapp, params) {
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
module.exports.findAllIdApp = async function (idapp) {
|
||||
const myfind = { idapp };
|
||||
module.exports.findAllIdApp = async function (idapp, code) {
|
||||
let myfind = { idapp };
|
||||
|
||||
if (code) {
|
||||
myfind = { ...myfind, code }
|
||||
}
|
||||
|
||||
// return await Product.find(myfind);
|
||||
|
||||
const query = [
|
||||
{ $match: { idapp } },
|
||||
{ $match: myfind },
|
||||
{ "$addFields": { "myidProd": { "$toObjectId": "$idProducer" } } },
|
||||
{
|
||||
$lookup: {
|
||||
@@ -125,6 +145,10 @@ module.exports.getProductByTitle = function (query, sort, callback) {
|
||||
Product.find(query, null, sort, callback)
|
||||
}
|
||||
|
||||
module.exports.getProductByCode = function (idapp, code) {
|
||||
return Product.findOne({ idapp, code })
|
||||
}
|
||||
|
||||
module.exports.filterProductByDepartment = function (department, callback) {
|
||||
let regexp = new RegExp(`${department}`, 'i')
|
||||
var query = { department: { $regex: regexp } };
|
||||
|
||||
Reference in New Issue
Block a user