2025-02-03 17:18:27 +01:00
|
|
|
const mongoose = require('mongoose').set('debug', false)
|
|
|
|
|
const Schema = mongoose.Schema;
|
|
|
|
|
|
|
|
|
|
const tools = require('../tools/general');
|
|
|
|
|
const { ObjectId } = require('mongodb');
|
|
|
|
|
|
2025-02-10 22:48:46 +01:00
|
|
|
const { IImg } = require('../models/myscheda');
|
|
|
|
|
|
2025-02-03 17:18:27 +01:00
|
|
|
mongoose.Promise = global.Promise;
|
|
|
|
|
mongoose.level = "F";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Resolving error Unknown modifier: $pushAll
|
|
|
|
|
mongoose.plugin(schema => {
|
|
|
|
|
schema.options.usePushEach = true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const CatalogSchema = new Schema({
|
|
|
|
|
idapp: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
active: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false,
|
|
|
|
|
},
|
|
|
|
|
title: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
2025-02-10 22:48:46 +01:00
|
|
|
foto_collana: IImg,
|
2025-02-05 12:13:27 +01:00
|
|
|
idCollane: [{
|
|
|
|
|
type: Number,
|
|
|
|
|
}],
|
2025-02-11 18:57:57 +01:00
|
|
|
argomenti: [{
|
|
|
|
|
type: String,
|
|
|
|
|
}],
|
2025-02-10 22:48:46 +01:00
|
|
|
editore: [{ type: String }],
|
2025-02-03 17:18:27 +01:00
|
|
|
descr_introduttiva: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
2025-02-05 12:13:27 +01:00
|
|
|
idPageAssigned: {
|
2025-02-03 17:18:27 +01:00
|
|
|
type: String,
|
|
|
|
|
},
|
2025-02-11 18:57:57 +01:00
|
|
|
idPageAssigned_stampa: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
2025-02-03 17:18:27 +01:00
|
|
|
referenti: [{
|
|
|
|
|
type: String,
|
|
|
|
|
}],
|
|
|
|
|
|
2025-02-10 22:48:46 +01:00
|
|
|
img_bordata: IImg,
|
|
|
|
|
img_intro: IImg,
|
2025-02-11 18:57:57 +01:00
|
|
|
img_bordata_stampa: IImg,
|
|
|
|
|
img_intro_stampa: IImg,
|
2025-02-10 22:48:46 +01:00
|
|
|
pagina_introduttiva_sfondo_nero: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
},
|
2025-02-03 17:18:27 +01:00
|
|
|
|
2025-02-10 22:48:46 +01:00
|
|
|
pdf_generato: String,
|
|
|
|
|
data_generato: {
|
|
|
|
|
type: Date,
|
|
|
|
|
},
|
|
|
|
|
pdf_online: String,
|
|
|
|
|
data_online: {
|
|
|
|
|
type: Date,
|
|
|
|
|
},
|
2025-02-03 17:18:27 +01:00
|
|
|
|
|
|
|
|
date_created: {
|
|
|
|
|
type: Date,
|
|
|
|
|
default: Date.now
|
|
|
|
|
},
|
|
|
|
|
date_updated: {
|
|
|
|
|
type: Date,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2025-02-11 18:57:57 +01:00
|
|
|
/*
|
|
|
|
|
TOLTO ALTRIMENTI su /settable non mi crea l'ID
|
2025-02-03 17:18:27 +01:00
|
|
|
CatalogSchema.pre('save', async function (next) {
|
|
|
|
|
if (this.isNew) {
|
|
|
|
|
this._id = new ObjectId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
next();
|
|
|
|
|
});
|
2025-02-11 18:57:57 +01:00
|
|
|
*/
|
2025-02-03 17:18:27 +01:00
|
|
|
|
|
|
|
|
CatalogSchema.statics.getFieldsForSearch = function () {
|
|
|
|
|
return [{ field: 'title', type: tools.FieldType.string }]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CatalogSchema.statics.executeQueryTable = function (idapp, params, user) {
|
|
|
|
|
params.fieldsearch = this.getFieldsForSearch();
|
|
|
|
|
return tools.executeQueryTable(this, idapp, params, user);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CatalogSchema.statics.findAllIdApp = async function (idapp) {
|
|
|
|
|
const Catalog = this;
|
|
|
|
|
|
2025-02-05 12:13:27 +01:00
|
|
|
const arrrec = await Catalog.aggregate([
|
|
|
|
|
// Filtra i documenti per idapp
|
|
|
|
|
{ $match: { idapp } },
|
|
|
|
|
|
|
|
|
|
// Ordina i risultati per titolo
|
|
|
|
|
{ $sort: { title: 1 } },
|
|
|
|
|
|
|
|
|
|
// Esegui il join con la collezione Collana
|
|
|
|
|
{
|
|
|
|
|
$lookup: {
|
|
|
|
|
from: "collanas", // Nome della collezione Collana
|
|
|
|
|
localField: "idCollane", // Campo in Catalog
|
|
|
|
|
foreignField: "idCollana", // Campo in Collana
|
|
|
|
|
as: "collana_info" // Nome del campo che conterrà i risultati del join
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-02-03 17:18:27 +01:00
|
|
|
|
2025-02-05 12:13:27 +01:00
|
|
|
]);
|
2025-02-03 17:18:27 +01:00
|
|
|
|
|
|
|
|
return arrrec;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const Catalog = mongoose.model('Catalog', CatalogSchema);
|
|
|
|
|
|
2025-03-03 00:46:08 +01:00
|
|
|
Catalog.createIndexes()
|
|
|
|
|
.then(() => { })
|
|
|
|
|
.catch((err) => { throw err; });
|
|
|
|
|
|
2025-02-03 17:18:27 +01:00
|
|
|
|
|
|
|
|
module.exports = { Catalog };
|