- aggiunto componenti per Home Template... ma ancora da provare

- sistemato catprods
- Sistemato menu
This commit is contained in:
Surya Paolo
2025-09-22 19:09:02 +02:00
parent 4a05ddee50
commit 08cf4b6d9f
31 changed files with 475 additions and 31 deletions

View File

@@ -0,0 +1,17 @@
// @ts-check
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const EventSchema = new Schema({
title: { type: String, required: true },
start: { type: Date, required: true, index: true },
end: { type: Date },
place: String,
teaser: String,
cover: String,
to: String,
createdAt: { type: Date, default: Date.now }
}, { collection: 'events', versionKey: false });
var EventModel = module.exports = mongoose.model('Event', EventSchema);

63
src/server/models/Home.js Normal file
View File

@@ -0,0 +1,63 @@
// @ts-check
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
mongoose.level = "F";
const HeroSchema = new Schema({
title: { type: String, required: true },
subtitle: String,
badge: String,
mediaUrl: { type: String, required: true },
ctas: [{ label: String, to: String, href: String }]
}, { _id: false });
const PillarSchema = new Schema({
id: { type: String, required: true },
icon: { type: String, required: true },
title: { type: String, required: true },
excerpt: String,
to: String
}, { _id: false });
const TestimonialSchema = new Schema({
id: String, quote: String, author: String, role: String, avatar: String
}, { _id: false });
const GallerySchema = new Schema({
id: String, src: String, alt: String
}, { _id: false });
const FaqSchema = new Schema({
q: String, a: String
}, { _id: false });
const PostLiteSchema = new Schema({
id: String, title: String, date: String, category: String, teaser: String, cover: String, to: String
}, { _id: false });
const PartnerSchema = new Schema({
id: String, name: String, logo: String, href: String
}, { _id: false });
const HomeSchema = new Schema({
hero: { type: HeroSchema, required: true },
pillars: { type: [PillarSchema], default: [] },
testimonials: { type: [TestimonialSchema], default: [] },
gallery: { type: [GallerySchema], default: [] },
faq: { type: [FaqSchema], default: [] },
posts: { type: [PostLiteSchema], default: [] },
partners: { type: [PartnerSchema], default: [] },
meta: { title: String, description: String, ogImage: String },
updatedAt: { type: Date, default: Date.now }
}, { collection: 'home', versionKey: false });
HomeSchema.pre('save', function(next) {
this.set('updatedAt', new Date());
next();
});
var HomeModel = module.exports = mongoose.model('Home', HomeSchema);

16
src/server/models/Post.js Normal file
View File

@@ -0,0 +1,16 @@
// @ts-check
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const PostSchema = new Schema({
title: { type: String, required: true },
date: { type: Date, required: true, index: true },
category: String,
teaser: String,
cover: String,
to: String,
bodyMd: String,
createdAt: { type: Date, default: Date.now }
}, { collection: 'posts', versionKey: false });
var PostModel = module.exports = mongoose.model('Post', PostSchema);

View File

@@ -121,7 +121,7 @@ CatProdSchema.statics.getCatProdWithTitleCount = async function (idapp, updateda
input: "$products",
as: "prod",
cond: {
$in: ["$$prod.idStatoProdotto", [1, 4, 34, 45, 46]]
$in: ["$$prod.productInfo.idStatoProdotto", [1, 4, 34, 45, 46]]
}
}
}
@@ -152,6 +152,8 @@ CatProdSchema.statics.getCatProdWithTitleCount = async function (idapp, updateda
const result = await CatProd.aggregate(myquery);
// console.log(JSON.stringify(myquery, null, 2))
if (updatedata) {
for (const record of result) {
await CatProd.updateOne(

View File

@@ -76,7 +76,7 @@ module.exports.getCollaneWithTitleCount = async function (idapp, updatedata) {
input: "$products",
as: "prod",
cond: {
$in: ["$$prod.idStatoProdotto", [1, 4, 34, 45, 46]]
$in: ["$$prod.productInfo.idStatoProdotto", [1, 4, 34, 45, 46]]
}
}
}

View File

@@ -977,14 +977,6 @@ module.exports.getArrCatProds = async function (idapp, cosa) {
let myquery = [
...addquery,
{
$lookup: {
from: 'productinfos',
localField: 'idProductInfo',
foreignField: '_id',
as: 'productInfo',
},
},
{
$lookup: {
from: 'catprods',
@@ -1015,6 +1007,10 @@ module.exports.getArrCatProds = async function (idapp, cosa) {
let arr = [];
arr = await Product.aggregate(myquery);
if (cosa !== shared_consts.PROD.GAS) {
// console.log(JSON.stringify(myquery, null, 2))
}
// arr = result.map(category => category.name);
return arr;
} catch (e) {

View File

@@ -68,7 +68,7 @@ module.exports.getEditoriWithTitleCount = async function (idapp, updatedata) {
input: "$products",
as: "prod",
cond: {
$in: ["$$prod.idStatoProdotto", [1, 4, 34, 45, 46]]
$in: ["$$prod.productInfo.idStatoProdotto", [1, 4, 34, 45, 46]]
}
}
}