Develop PDB 1

This commit is contained in:
Surya Paolo
2023-11-28 14:20:22 +01:00
parent 5aa6accfc5
commit a66cd610dd
4 changed files with 43 additions and 8 deletions

View File

@@ -1,9 +1,11 @@
const mongoose = require('mongoose').set('debug', false) const mongoose = require('mongoose').set('debug', false)
const Schema = mongoose.Schema; const Schema = mongoose.Schema;
mongoose.Promise = global.Promise; mongoose.Promise = global.Promise;
mongoose.level = "F"; mongoose.level = "F";
const tools = require('../tools/general');
// Resolving error Unknown modifier: $pushAll // Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => { mongoose.plugin(schema => {
@@ -11,20 +13,41 @@ mongoose.plugin(schema => {
}); });
const CategorySchema = new Schema({ const CategorySchema = new Schema({
idapp: {
type: String,
},
name: { name: {
type: String, type: String,
unique: true, unique: true,
index: true, index: true,
lowercase: true },
} img: {
type: String,
},
}); });
module.exports.getAllCategories = function (callback) { CategorySchema.statics.getAllCategories = function (callback) {
Category.find(callback) Category.find(callback)
} }
module.exports.getCategoryById = function (id, callback) { CategorySchema.statics.getCategoryById = function (id, callback) {
Category.findById(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 };

View File

@@ -27,7 +27,6 @@ const productSchema = new Schema({
], ],
code: { code: {
type: String, type: String,
lowercase: true
}, },
name: { name: {
type: String, type: String,
@@ -39,8 +38,13 @@ const productSchema = new Schema({
type: String, ref: 'Department' type: String, ref: 'Department'
}, },
category: { category: {
type: String, ref: 'Category' type: Array,
// type: String },
prezzo_ivato: {
type: Number
},
perc_iva: { // 4, 10, 22 &
type: Number
}, },
price: { price: {
type: Number type: Number

View File

@@ -66,6 +66,7 @@ const Cart = require('../models/cart');
const OrdersCart = require('../models/orderscart'); const OrdersCart = require('../models/orderscart');
const Storehouse = require('../models/storehouse'); const Storehouse = require('../models/storehouse');
const Department = require('../models/department'); const Department = require('../models/department');
const { Category } = require('../models/category');
const Group = require('../models/group'); const Group = require('../models/group');
const tools = require('../tools/general'); 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')) { if ((mydata['_id'] === undefined || mydata['_id'] === '' || (mytablerec.isNew && mydata['_id'] === 0)) && (mytablerec._id === undefined || mytablerec._id === '0')) {
mytablerec._id = new ObjectID(); mytablerec._id = new ObjectID();
mydata._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 workers = User.getusersWorkersList(idapp);
let storehouses = Storehouse.findAllIdApp(idapp); let storehouses = Storehouse.findAllIdApp(idapp);
let departments = Department.findAllIdApp(idapp); let departments = Department.findAllIdApp(idapp);
let categories = Category.findAllIdApp(idapp);
// SKILLS: // SKILLS:
let levels = Level.findAllIdApp(idapp); let levels = Level.findAllIdApp(idapp);
@@ -1486,6 +1489,7 @@ function load(req, res, version) {
mygroups, mygroups,
listcircuits, // 37 listcircuits, // 37
myelems, // 38 myelems, // 38
categories, // 39
]).then((arrdata) => { ]).then((arrdata) => {
// console.table(arrdata); // console.table(arrdata);
let myuser = req.user; let myuser = req.user;
@@ -1567,6 +1571,7 @@ function load(req, res, version) {
mygroups: arrdata[36], mygroups: arrdata[36],
listcircuits: arrdata[37], listcircuits: arrdata[37],
myelems: arrdata[38], myelems: arrdata[38],
categories: arrdata[39],
}); });
} }

View File

@@ -61,6 +61,7 @@ const Cart = require('../models/cart');
const OrdersCart = require('../models/orderscart'); const OrdersCart = require('../models/orderscart');
const Storehouse = require('../models/storehouse'); const Storehouse = require('../models/storehouse');
const Department = require('../models/department'); const Department = require('../models/department');
const { Category } = require('../models/category');
const ShareWithUs = require('../models/sharewithus'); const ShareWithUs = require('../models/sharewithus');
const Site = require('../models/site'); const Site = require('../models/site');
const IscrittiConacreis = require('../models/iscrittiConacreis'); const IscrittiConacreis = require('../models/iscrittiConacreis');
@@ -105,6 +106,8 @@ module.exports = {
mytable = Storehouse; mytable = Storehouse;
else if (tablename === 'departments') else if (tablename === 'departments')
mytable = Department; mytable = Department;
else if (tablename === 'categorys')
mytable = Category;
else if (tablename === 'sharewithus') else if (tablename === 'sharewithus')
mytable = ShareWithUs; mytable = ShareWithUs;
else if (tablename === 'sites') else if (tablename === 'sites')