- catalogo avanti, parte 1

This commit is contained in:
Surya Paolo
2024-05-04 14:49:02 +02:00
parent e1f2e799d6
commit 07973fbf0a
14 changed files with 639 additions and 171 deletions

54
src/server/models/author.js Executable file
View File

@@ -0,0 +1,54 @@
mongoose = require('mongoose').set('debug', false)
const Schema = mongoose.Schema;
const tools = require('../tools/general');
mongoose.Promise = global.Promise;
mongoose.level = "F";
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
const AuthorSchema = new Schema({
idapp: {
type: String,
},
name: {
type: String,
},
surname: {
type: String,
},
bio: {
type: String,
},
img: {
type: String,
},
});
var Author = module.exports = mongoose.model('Author', AuthorSchema);
module.exports.getFieldsForSearch = function () {
return [
{ field: 'name', type: tools.FieldType.string },
{ field: 'surname', type: tools.FieldType.string },
]
};
module.exports.executeQueryTable = function (idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, idapp, params);
};
module.exports.findAllIdApp = async function (idapp) {
const myfind = { idapp };
return await Author.find(myfind);
};
module.exports.createIndexes((err) => {
if (err) throw err;
});

View File

@@ -743,8 +743,8 @@ CircuitSchema.statics.sendCoins = async function (onlycheck, idapp, usernameOrig
};
await Circuit.updateOne({ _id: circuittable }, { $set: paramstoupdate });
extrarec.saldoOrig = accountorigTable.saldo;
extrarec.saldoDest = accountdestTable.saldo;
extrarec.saldoOrig = tools.arrotondaA2Decimali(accountorigTable.saldo);
extrarec.saldoDest = tools.arrotondaA2Decimali(accountdestTable.saldo);
let orig = usernameOrig;
if (extrarec.grouporig) {

View File

@@ -33,6 +33,9 @@ const productSchema = new Schema({
type: Boolean,
default: true,
},
isbn: {
type: String,
},
idProductInfo: { type: Schema.Types.ObjectId, ref: 'ProductInfo' },
idProducer: { type: Schema.Types.ObjectId, ref: 'Producer' },
idStorehouses: [
@@ -146,6 +149,9 @@ const productSchema = new Schema({
note: {
type: String,
},
versione: {
type: Number,
},
producer_name: {
type: String,
},
@@ -346,6 +352,14 @@ module.exports.findAllIdApp = async function (idapp, code, id, all) {
preserveNullAndEmptyArrays: true,
},
},
{
$lookup: {
from: 'authors',
localField: 'productInfo.idAuthors',
foreignField: '_id',
as: 'productInfo.authors'
}
},
{
$lookup: {
from: 'catprods',
@@ -836,8 +850,8 @@ module.exports.singlerecconvert_AfterImport_AndSave = async function (idapp, pro
ris = await Product.updateOne({ _id: ObjectID(prod._id) }, { $unset: objDelete })
if (ris) {
console.log('ris', ris);
if (ris && ris.nModified > 0) {
console.log('Modificato: ', objtoset.name);
}
// const campodarimuovere = 'producer_name';

View File

@@ -88,6 +88,9 @@ const productInfoSchema = new Schema({
img3: {
type: String,
},
img4: {
type: String,
},
ingredienti: {
type: String,
},
@@ -97,18 +100,20 @@ const productInfoSchema = new Schema({
note: {
type: String,
},
author: {
type: String,
},
idAuthors: [{ type: Schema.Types.ObjectId, ref: 'Author' }],
idPublisher: { type: Schema.Types.ObjectId, ref: 'Publisher' },
collezione: {
type: String,
},
publisher: { //editore
type: String,
date_publishing: {
type: Date,
},
numpages: {
type: Number,
},
productType: {
type: Number,
},
});
@@ -163,6 +168,14 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
as: 'catprods'
}
},
{
$lookup: {
from: 'authors',
localField: 'idAuthors',
foreignField: '_id',
as: 'authors'
}
},
{
$lookup: {
from: 'subcatprods',

50
src/server/models/publisher.js Executable file
View File

@@ -0,0 +1,50 @@
mongoose = require('mongoose').set('debug', false)
const Schema = mongoose.Schema;
const tools = require('../tools/general');
mongoose.Promise = global.Promise;
mongoose.level = "F";
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
const PublisherSchema = new Schema({
idapp: {
type: String,
},
name: {
type: String,
},
link: {
type: String,
},
img: {
type: String,
},
});
var Publisher = module.exports = mongoose.model('Publisher', PublisherSchema);
module.exports.getFieldsForSearch = function () {
return [
{ field: 'name', type: tools.FieldType.string },
]
};
module.exports.executeQueryTable = function (idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, idapp, params);
};
module.exports.findAllIdApp = async function (idapp) {
const myfind = { idapp };
return await Publisher.find(myfind);
};
module.exports.createIndexes((err) => {
if (err) throw err;
});

View File

@@ -5721,6 +5721,25 @@ UserSchema.statics.tooManyReqPassword = async function (idapp, email, set) {
}
};
UserSchema.statics.tooManyLoginWrong = async function (idapp, username, set) {
const User = this;
const maxnum = 30;
const user = await User.findByUsername(idapp, username, true, false);
if (user) {
if (!user.retry_pwd)
user.retry_pwd = 0
if (set && user.retry_pwd <= maxnum) {
user.retry_pwd++;
await User.findOneAndUpdate({ _id: user._id }, { $set: { retry_pwd: user.retry_pwd } });
}
return {troppilogin: user.retry_pwd > maxnum, retry_pwd: user.retry_pwd};
}
return {troppilogin: false, retry_pwd: 0};
};
UserSchema.statics.setLastCircuitOpened = async function (idapp, username, circuitpath) {