This commit is contained in:
Paolo Arena
2021-01-18 00:48:17 +01:00
parent 142380e54b
commit 5493953b58
22 changed files with 9749 additions and 231 deletions

View File

@@ -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 } };