++ aggiunta la prenotazione negli eventi. con la lista degli utenti.

This commit is contained in:
Surya Paolo
2023-04-17 00:11:36 +02:00
parent eea6e63c58
commit 0945f1af08
22 changed files with 636 additions and 157 deletions

View File

@@ -473,6 +473,14 @@ const UserSchema = new mongoose.Schema({
tab: { type: Number },
},
],
attend: [
{
_id: false,
id: { type: String },
tab: { type: Number },
num: { type: Number },
},
],
version: { type: Number },
},
});
@@ -1614,6 +1622,7 @@ UserSchema.statics.getUserProfileByUsername = async function (
'profile.friends': 1,
'profile.favorite': 1,
'profile.bookmark': 1,
'profile.attend': 1,
'profile.seen': 1,
email: 1,
date_reg: 1,
@@ -1661,6 +1670,7 @@ UserSchema.statics.getUserProfileByUsername = async function (
'profile.friends': 1,
'profile.favorite': 1,
'profile.bookmark': 1,
'profile.attend': 1,
'profile.seen': 1,
email: 1,
date_reg: 1,
@@ -1709,6 +1719,7 @@ UserSchema.statics.getUserProfileByUsername = async function (
'profile.friends': 1,
'profile.favorite': 1,
'profile.bookmark': 1,
'profile.attend': 1,
'profile.seen': 1,
'mycities': 1,
'comune': 1,
@@ -1934,7 +1945,7 @@ UserSchema.statics.addFavorite = async function (
// Invia una Notifica al Destinatario
const recObjCreator = await globalTables.getUserCreatorByNumTabAndId(idapp, id, tab);
if (recObjCreator) {
await SendNotif.createNewNotifToSingleUser(req, null, { usernameDest: recObjCreator.username, recObjCreator, username_action: req.user.username }, false, shared_consts.TypeNotifs.TYPEDIR_FAVORITE,
shared_consts.TypeNotifs.ID_FAVORITE_ADDED);
@@ -1943,6 +1954,29 @@ UserSchema.statics.addFavorite = async function (
return ris;
};
// Aggiungo il Partecipa
UserSchema.statics.addAttend = async function (
req, idapp, username, id, tab, num) {
const ris = await User.updateOne({ idapp, username },
{ $push: { 'profile.attend': { id, tab, num } } });
const { SendNotif } = require('../models/sendnotif');
const globalTables = require('../tools/globalTables');
// Invia una Notifica al Destinatario
const recObjCreator = await globalTables.getUserCreatorByNumTabAndId(idapp, id, tab);
if (recObjCreator) {
await SendNotif.createNewNotifToSingleUser(req, null, { usernameDest: recObjCreator.username, recObjCreator, username_action: req.user.username }, false,
shared_consts.TypeNotifs.TYPEDIR_EVENTS,
shared_consts.TypeNotifs.ID_EVENTS_ATTEND);
}
return ris;
};
// Rimuovo il Bookmark
UserSchema.statics.removeBookmark = async function (
idapp, username, id, tab) {
@@ -1956,6 +1990,13 @@ UserSchema.statics.addBookmark = async function (
return await User.updateOne({ idapp, username },
{ $push: { 'profile.bookmark': { id, tab } } });
};
// Rimuovo il Partecipa
UserSchema.statics.removeAttend = async function (
idapp, username, id, tab) {
return await User.updateOne({ idapp, username },
{ $pull: { 'profile.attend': { id: { $in: [id] }, tab } } });
};
// Aggiungo il Bookmark
UserSchema.statics.addSeen = async function (
idapp, username, id, tab) {
@@ -2816,6 +2857,7 @@ function getWhatToShow(idapp, username) {
'profile.handshake': 1,
'profile.favorite': 1,
'profile.bookmark': 1,
'profile.attend': 1,
'profile.seen': 1,
};
@@ -2842,6 +2884,7 @@ function getWhatToShow_Unknown(idapp, username) {
'profile.friends': 1,
'profile.favorite': 1,
'profile.bookmark': 1,
'profile.attend': 1,
'profile.seen': 1,
}
}
@@ -2871,6 +2914,7 @@ UserSchema.statics.getWhatToShow_IfFriends = async function (idapp, username) {
'profile.friends': 1,
'profile.favorite': 1,
'profile.bookmark': 1,
'profile.attend': 1,
'profile.seen': 1,
};
@@ -4717,18 +4761,20 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, v
if (version) {
let versattualeuser = 0;
if (!recUser.profile.version) {
if (!recUser.profile.version) {
recUser.version = 0;
versattualeuser = 0;
} else {
versattualeuser = recUser.profile.version;
}
versattualeuser = 0;
if (versattualeuser < version) {
// Aggiornamento versione
recUser = await User.updateVersion(versattualeuser, recUser);
await User.findOneAndUpdate({_id: recUser._id}, {$set: { 'profile.version' : version }});
await User.findOneAndUpdate({ _id: recUser._id }, { $set: { 'profile.version': version } });
}
}
@@ -4818,7 +4864,7 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, v
};
UserSchema.statics.updateVersion = async function (userversion, recUser) {
const { MySkill } = require('../models/myskill');
const { MyGood } = require('../models/mygood');
const { City } = require('../models/city');
@@ -4828,27 +4874,40 @@ UserSchema.statics.updateVersion = async function (userversion, recUser) {
recUser.profile.notifs = shared_consts.DEFAULT_NOTIFS_USER;
}
const recfavoriteNotif = recUser.profile.notifs.find((rec) => rec.dir === 11);
if (!recfavoriteNotif){
recUser.profile.notifs.push( { dir: 11, value: 1 })
const recfavoriteNotif = recUser.profile.notifs.find((rec) => rec.dir === shared_consts.TypeNotifs.TYPEDIR_FAVORITE);
if (!recfavoriteNotif) {
recUser.profile.notifs.push({ dir: shared_consts.TypeNotifs.TYPEDIR_FAVORITE, value: shared_consts.TypeNotifs.ID_FAVORITE_ADDED })
}
const recAttendNotif = recUser.profile.notifs.find((rec) => rec.dir === shared_consts.TypeNotifs.TYPEDIR_EVENTS);
if (recAttendNotif) {
if (!tools.isBitActive(recAttendNotif.value, shared_consts.TypeNotifs.ID_EVENTS_ATTEND)) {
recAttendNotif.value = tools.SetBit(recAttendNotif.value, shared_consts.TypeNotifs.ID_EVENTS_ATTEND);
}
for (let i = 0; i < recUser.profile.notifs.length; i++) {
if (recUser.profile.notifs[i].dir === shared_consts.TypeNotifs.TYPEDIR_EVENTS)
recUser.profile.notifs[i].value = recAttendNotif.value;
}
}
// Imposta la provincia, se non l'ho messa, in base al bene o servizio che hai messo.
if (!recUser.profile.resid_province) {
let resid_province = '';
const firstrec = await MySkill.findOne({userId: recUser._id}).lean();
const firstrec = await MySkill.findOne({ userId: recUser._id }).lean();
if (firstrec && firstrec.idCity && firstrec.idCity.length > 0) {
resid_province = await City.getProvinceByIdCity(firstrec.idCity[0]);
resid_province = await City.getProvinceByIdCity(firstrec.idCity[0]);
} else {
const firstrec = await MyGood.findOne({userId: recUser._id}).lean();
const firstrec = await MyGood.findOne({ userId: recUser._id }).lean();
if (firstrec && firstrec.idCity && firstrec.idCity.length === 1) {
resid_province = await City.getProvinceByIdCity(firstrec.idCity[0]);
}
}
if (resid_province) {
await User.findOneAndUpdate({_id: recUser._id}, {$set: {'profile.resid_province': resid_province}});
await User.findOneAndUpdate({ _id: recUser._id }, { $set: { 'profile.resid_province': resid_province } });
}
}
@@ -4861,7 +4920,7 @@ UserSchema.statics.updateVersion = async function (userversion, recUser) {
}
}
await User.findOneAndUpdate({_id: recUser._id}, {$set: { 'profile.notifs': recUser.profile.notifs }});
await User.findOneAndUpdate({ _id: recUser._id }, { $set: { 'profile.notifs': recUser.profile.notifs } });
}
return recUser;