From a66cd610dd91934ff2d42964bf4cb6d68c2fdadc Mon Sep 17 00:00:00 2001 From: Surya Paolo Date: Tue, 28 Nov 2023 14:20:22 +0100 Subject: [PATCH] Develop PDB 1 --- src/server/models/category.js | 33 ++++++++++++++++++++++++++----- src/server/models/product.js | 10 +++++++--- src/server/router/index_router.js | 5 +++++ src/server/tools/globalTables.js | 3 +++ 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/server/models/category.js b/src/server/models/category.js index c04fe2c..384af4e 100755 --- a/src/server/models/category.js +++ b/src/server/models/category.js @@ -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 }; diff --git a/src/server/models/product.js b/src/server/models/product.js index ec5e47f..91256b7 100755 --- a/src/server/models/product.js +++ b/src/server/models/product.js @@ -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 diff --git a/src/server/router/index_router.js b/src/server/router/index_router.js index be2128b..960f8bf 100755 --- a/src/server/router/index_router.js +++ b/src/server/router/index_router.js @@ -66,6 +66,7 @@ const Cart = require('../models/cart'); const OrdersCart = require('../models/orderscart'); const Storehouse = require('../models/storehouse'); const Department = require('../models/department'); +const { Category } = require('../models/category'); const Group = require('../models/group'); const tools = require('../tools/general'); @@ -373,6 +374,7 @@ router.post('/settable', authenticate, async (req, res) => { if ((mydata['_id'] === undefined || mydata['_id'] === '' || (mytablerec.isNew && mydata['_id'] === 0)) && (mytablerec._id === undefined || mytablerec._id === '0')) { mytablerec._id = new ObjectID(); mydata._id = new ObjectID(); + mytablerec.isNew = true; } } @@ -1403,6 +1405,7 @@ function load(req, res, version) { let workers = User.getusersWorkersList(idapp); let storehouses = Storehouse.findAllIdApp(idapp); let departments = Department.findAllIdApp(idapp); + let categories = Category.findAllIdApp(idapp); // SKILLS: let levels = Level.findAllIdApp(idapp); @@ -1486,6 +1489,7 @@ function load(req, res, version) { mygroups, listcircuits, // 37 myelems, // 38 + categories, // 39 ]).then((arrdata) => { // console.table(arrdata); let myuser = req.user; @@ -1567,6 +1571,7 @@ function load(req, res, version) { mygroups: arrdata[36], listcircuits: arrdata[37], myelems: arrdata[38], + categories: arrdata[39], }); } diff --git a/src/server/tools/globalTables.js b/src/server/tools/globalTables.js index 043b332..9613577 100755 --- a/src/server/tools/globalTables.js +++ b/src/server/tools/globalTables.js @@ -61,6 +61,7 @@ const Cart = require('../models/cart'); const OrdersCart = require('../models/orderscart'); const Storehouse = require('../models/storehouse'); const Department = require('../models/department'); +const { Category } = require('../models/category'); const ShareWithUs = require('../models/sharewithus'); const Site = require('../models/site'); const IscrittiConacreis = require('../models/iscrittiConacreis'); @@ -105,6 +106,8 @@ module.exports = { mytable = Storehouse; else if (tablename === 'departments') mytable = Department; + else if (tablename === 'categorys') + mytable = Category; else if (tablename === 'sharewithus') mytable = ShareWithUs; else if (tablename === 'sites')