- aggiunto il Comune di Residenza alla REgistrazione e al Tutorial

This commit is contained in:
Surya Paolo
2025-11-27 00:48:58 +01:00
parent 18790ee379
commit acb685f819
12 changed files with 134 additions and 116 deletions

View File

@@ -16,7 +16,7 @@ const { ObjectId } = require('mongodb');
const tableModel = shared_consts.TABLES_ATTIVITAS;
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
mongoose.plugin((schema) => {
schema.options.usePushEach = true;
});
@@ -44,9 +44,9 @@ const AttivitaSchema = new Schema(
idCity: [
{
type: Number,
}],
logo:
{
},
],
logo: {
imagefile: {
type: String,
},
@@ -68,7 +68,8 @@ const AttivitaSchema = new Schema(
description: {
type: String,
},
}],
},
],
note: {
type: String,
default: '',
@@ -107,7 +108,7 @@ const AttivitaSchema = new Schema(
coordinates: {
type: [Number], // L'array dovrebbe contenere lon e lat
required: false,
index: '2dsphere' // Indice geospaziale [lng, lat]
index: '2dsphere', // Indice geospaziale [lng, lat]
},
},
@@ -123,23 +124,21 @@ const AttivitaSchema = new Schema(
whatsapp: {
type: String,
},
createdBy: { // Username del creatore (proponente)
createdBy: {
// Username del creatore (proponente)
type: String,
},
//**ADDFIELD_ATTIVITA
},
...Reaction.getFieldsForReactions(),
...tools.getFieldsForAnnunci()
}, { strict: false });
...tools.getFieldsForAnnunci(),
},
);
AttivitaSchema.pre('save', async function (next) {
if (this.isNew) {
if (!this.date_created)
this.date_created = new Date();
if (!this.date_created) this.date_created = new Date();
}
next();
@@ -148,15 +147,11 @@ AttivitaSchema.pre('save', async function (next) {
AttivitaSchema.statics.findAllIdApp = async function (idapp) {
const Attivita = this;
const query = [
{ $match: { idapp } },
{ $sort: { descr: 1 } },
];
const query = [{ $match: { idapp } }, { $sort: { descr: 1 } }];
return await Attivita.aggregate(query).then((arrrec) => {
return arrrec;
});
};
AttivitaSchema.statics.getFieldsForSearch = function () {
@@ -197,39 +192,37 @@ AttivitaSchema.statics.getMyRecById = function (idapp, idSkill) {
let query = [
{
'$match': {
'_id': idSkill, idapp
$match: {
_id: idSkill,
idapp,
},
},
{
'$sort': {
'desc': 1,
$sort: {
desc: 1,
},
},
{
'$addFields': {
'myId1': {
'$toObjectId': '$userId',
$addFields: {
myId1: {
$toObjectId: '$userId',
},
},
},
{
'$lookup': {
'from': 'users',
'localField': 'myId1',
'foreignField': '_id',
'as': 'user',
$lookup: {
from: 'users',
localField: 'myId1',
foreignField: '_id',
as: 'user',
},
},
{
'$replaceRoot': {
'newRoot': {
'$mergeObjects': [
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
'$arrayElemAt': [
'$user',
0,
],
$arrayElemAt: ['$user', 0],
},
'$$ROOT',
],
@@ -240,22 +233,19 @@ AttivitaSchema.statics.getMyRecById = function (idapp, idSkill) {
$project: shared_consts.getProjectForAll({}, tableModel),
},
{
'$lookup': {
'from': 'skills',
'localField': 'idSkill',
'foreignField': '_id',
'as': 'recSkill',
$lookup: {
from: 'skills',
localField: 'idSkill',
foreignField: '_id',
as: 'recSkill',
},
},
{
'$replaceRoot': {
'newRoot': {
'$mergeObjects': [
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
'$arrayElemAt': [
'$recSkill',
0,
],
$arrayElemAt: ['$recSkill', 0],
},
'$$ROOT',
],
@@ -266,22 +256,19 @@ AttivitaSchema.statics.getMyRecById = function (idapp, idSkill) {
$project: shared_consts.getProjectForAll({}, tableModel),
},
{
'$lookup': {
'from': 'sectors',
'localField': 'idSector',
'foreignField': '_id',
'as': 'sector',
$lookup: {
from: 'sectors',
localField: 'idSector',
foreignField: '_id',
as: 'sector',
},
},
{
'$replaceRoot': {
'newRoot': {
'$mergeObjects': [
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
'$arrayElemAt': [
'$sector',
0,
],
$arrayElemAt: ['$sector', 0],
},
'$$ROOT',
],
@@ -292,14 +279,11 @@ AttivitaSchema.statics.getMyRecById = function (idapp, idSkill) {
$project: shared_consts.getProjectForAll({}, tableModel),
},
{
'$replaceRoot': {
'newRoot': {
'$mergeObjects': [
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
'$arrayElemAt': [
'$attivita',
0,
],
$arrayElemAt: ['$attivita', 0],
},
'$$ROOT',
],
@@ -310,22 +294,19 @@ AttivitaSchema.statics.getMyRecById = function (idapp, idSkill) {
$project: shared_consts.getProjectForAll({}, tableModel),
},
{
'$lookup': {
'from': 'cities',
'localField': 'idCity',
'foreignField': '_id',
'as': 'mycities',
$lookup: {
from: 'cities',
localField: 'idCity',
foreignField: '_id',
as: 'mycities',
},
},
{
'$replaceRoot': {
'newRoot': {
'$mergeObjects': [
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
'$arrayElemAt': [
'$mycities',
0,
],
$arrayElemAt: ['$mycities', 0],
},
'$$ROOT',
],
@@ -374,24 +355,23 @@ AttivitaSchema.statics.getProject = function (proj_add2) {
//**ADDFIELD_ATTIVITA
};
const proj_add = shared_consts.getProjectForAll(proj_add2)
const proj_add = shared_consts.getProjectForAll(proj_add2);
return Object.assign({}, proj, proj_add);
}
};
AttivitaSchema.statics.getCompleteRecord = function (idapp, id) {
const Attivita = this;
return Attivita.getMyRecById(idapp, id);
};
const Attivita = mongoose.model('Attivita', AttivitaSchema);
Attivita.createIndexes()
.then(() => { })
.catch((err) => { throw err; });
.then(() => {})
.catch((err) => {
throw err;
});
module.exports = { Attivita };

View File

@@ -169,6 +169,8 @@ CitySchema.statics.executeQueryPickup = async function (idapp, params) {
{
$project: {
comune: { $concat: ["$comune", " (", "$prov", ")"] },
comune_solo: { $concat: ["$comune", ""] },
prov: 1,
},
},
];
@@ -189,6 +191,8 @@ CitySchema.statics.executeQueryPickup = async function (idapp, params) {
{
$project: {
comune: { $concat: ["$comune", " (", "$prov", ")"] },
comune_solo: { $concat: ["$comune", ""] },
prov: 1,
},
},
];

View File

@@ -103,7 +103,7 @@ const MySkillSchema = new Schema(
},
...Reaction.getFieldsForReactions(),
...tools.getFieldsForAnnunci()
}, { strict: false });
}, { strict: true });
MySkillSchema.index({ 'idapp': 1 });
@@ -340,6 +340,7 @@ MySkillSchema.statics.getMyRecById = function (idapp, idSkill) {
};
query = [...query, { ...toadd }];
return MySkill.aggregate(query).then((rec) => {
return rec ? rec[0] : null;

View File

@@ -1339,6 +1339,7 @@ sendNotifSchema.statics.getNotificationRecipients = async function (myrecnotifpa
username: 1,
'profile.notifs': 1,
'profile.mycircuits': 1,
'profile.resid_str_comune': 1,
'profile.resid_province': 1,
'profile.resid_card': 1,
'profile.notif_idCities': 1,

View File

@@ -5752,6 +5752,7 @@ UserSchema.statics.getQueryLastUsersStretteDiMano = async function (idapp) {
$first: {
profile: {
img: '$userfriend.profile.img',
resid_str_comune: '$userfriend.profile.resid_str_comune',
resid_province: '$userfriend.profile.resid_province',
note: '$userfriend.profile.note',
},
@@ -5765,6 +5766,7 @@ UserSchema.statics.getQueryLastUsersStretteDiMano = async function (idapp) {
$first: {
img: '$profile.img',
handshake: '$profile.handshake',
resid_str_comune: '$profile.resid_str_comune',
resid_province: '$profile.resid_province',
note: '$profile.note',
},