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

View File

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

View File

@@ -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],
});
}

View File

@@ -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')