++ 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

@@ -20,6 +20,12 @@ const bookingSchema = new Schema({
userId: {
type: String,
},
username: {
type: String,
},
tableType: {
type: Number,
},
id_bookedevent: {
type: String,
},

View File

@@ -9,6 +9,8 @@ const tools = require('../tools/general');
const { ObjectID } = require('mongodb');
const shared_consts = require('../tools/shared_nodejs');
const tableModel = shared_consts.TABLES_MYBACHECAS;
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true;
@@ -26,6 +28,7 @@ const MyBachecaSchema = new Schema({
required: true,
},
userId: { type: Schema.Types.ObjectId, ref: 'User' },
groupname: { type: String },
idSector: {
type: Number,
},
@@ -51,6 +54,30 @@ const MyBachecaSchema = new Schema({
dateTimeEnd: {
type: Date,
},
organisedBy: {
type: String
},
contact_phone: {
type: String
},
contact_telegram: {
type: String
},
address: {
type: String,
},
min_partecip: {
type: Number,
},
max_partecip: {
type: Number,
},
link_maplocation: {
type: String,
},
contribstr: {
type: String,
},
numLevel: {
type: Number,
default: 0,
@@ -137,7 +164,7 @@ MyBachecaSchema.statics.executeQueryTable = function (idapp, params, user) {
lk_FF: '_id',
lk_as: 'user',
af_objId_tab: 'myId',
lk_proj: this.getProject(),
lk_proj: shared_consts.getProjectForAll({}, tableModel),
},
};
@@ -151,25 +178,21 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
let myparsid = {
'_id': id,
idapp,
};
let query = [
{
'$match':
$match:
myparsid,
},
{
'$match': {
'idapp': idapp,
$sort: {
desc: 1,
},
},
{
'$sort': {
'desc': 1,
},
},
{
'$addFields': {
$addFields: {
'myId1': {
'$toObjectId': '$userId',
},
@@ -199,7 +222,7 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
},
},
{
'$project': this.getProject(),
'$project': shared_consts.getProjectForAll({}, tableModel),
},
{
'$lookup': {
@@ -225,7 +248,7 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
},
},
{
'$project': this.getProject(),
'$project': shared_consts.getProjectForAll({}, tableModel),
},
{
'$lookup': {
@@ -251,7 +274,7 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
},
},
{
'$project': this.getProject(),
'$project': shared_consts.getProjectForAll({}, tableModel),
},
/*{
'$lookup': {
@@ -277,7 +300,7 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
},
},
{
'$project': this.getProject(),
'$project': shared_consts.getProjectForAll({}, tableModel),
},
{
'$lookup': {
@@ -304,42 +327,26 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
},
];
let numtab = tools.getNumTabByTable(shared_consts.TABLES_MYBACHECAS);
try {
let numtab = tools.getNumTabByTable(shared_consts.TABLES_MYBACHECAS);
const objadd = tools.addNumFavoriteAndBookmarkToQuery(idapp, numtab);
query = [...query, ...objadd.query];
const objadd = tools.addNumFavoriteAndBookmarkToQuery(idapp, numtab);
query = [...query, ...objadd.query];
query = query.push(
{
$project: this.getProject(objadd.proj),
}
);
const toadd = {
$project: shared_consts.getProjectForAll(objadd.proj, tableModel),
};
query = [...query, { ...toadd }];
} catch (e) {
console.error('e', e);
}
return MyBacheca.aggregate(query).then((rec) => {
return rec ? rec[0] : null;
});
};
MyBachecaSchema.statics.getProject = function (proj_add2) {
let proj = {
recSkill: 1,
sector: 1,
idSector: 1,
idSkill: 1,
// 'idSubSkill': 1,
idStatusSkill: 1,
idContribType: 1,
dateTimeStart: 1,
dateTimeEnd: 1,
website: 1,
//**ADDFIELD_MYBACHECAS
};
const proj_add = shared_consts.getProjectForAll(proj_add2)
return Object.assign({}, proj, proj_add);
}
MyBachecaSchema.statics.getCompleteRecord = function (idapp, id) {
const MyBacheca = this;

View File

@@ -150,6 +150,7 @@ MyGoodSchema.statics.getMyRecById = function (idapp, idGood) {
let myparsid = {
'_id': idGood,
idapp,
};
let query = [
@@ -157,11 +158,6 @@ MyGoodSchema.statics.getMyRecById = function (idapp, idGood) {
'$match':
myparsid,
},
{
'$match': {
'idapp': idapp,
},
},
{
'$sort': {
'desc': 1,
@@ -309,11 +305,11 @@ MyGoodSchema.statics.getMyRecById = function (idapp, idGood) {
const objadd = tools.addNumFavoriteAndBookmarkToQuery(idapp, numtab);
query = [...query, ...objadd.query];
query = [...query,
{
$project: this.getProject(objadd.proj),
}
];
const toadd = {
$project: this.getProject(objadd.proj),
};
query = [...query, {...toadd}];
return MyGood.aggregate(query).then((rec) => {
return rec ? rec[0] : null;

View File

@@ -149,18 +149,13 @@ MyHospSchema.statics.executeQueryTable = function (idapp, params, user) {
MyHospSchema.statics.getMyRecById = function (idapp, id) {
const MyHosp = this;
const myparsid = { '_id': id };
const myparsid = { '_id': id, idapp };
let query = [
{
'$match':
myparsid,
},
{
'$match': {
'idapp': idapp,
},
},
{
'$sort': {
'desc': 1,
@@ -307,11 +302,11 @@ MyHospSchema.statics.getMyRecById = function (idapp, id) {
const objadd = tools.addNumFavoriteAndBookmarkToQuery(idapp, numtab);
query = [...query, ...objadd.query];
query = [...query,
{
$project: this.getProject(objadd.proj),
}
];
const toadd = {
$project: this.getProject(objadd.proj),
};
query = [...query, {...toadd}];
return MyHosp.aggregate(query).then((rec) => {
return rec ? rec[0] : null;

View File

@@ -156,12 +156,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
let query = [
{
'$match': {
'_id': idSkill,
},
},
{
'$match': {
'idapp': idapp,
'_id': idSkill, idapp
},
},
{
@@ -312,11 +307,11 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
const objadd = tools.addNumFavoriteAndBookmarkToQuery(idapp, numtab);
query = [...query, ...objadd.query];
query = [...query,
{
$project: this.getProject(objadd.proj),
}
];
const toadd = {
$project: this.getProject(objadd.proj),
};
query = [...query, {...toadd}];
return MySkill.aggregate(query).then((rec) => {
return rec ? rec[0] : null;

View File

@@ -17,14 +17,14 @@ const sendmsgSchema = new Schema({
},
source: {
page: { type: String },
event_id: { type: String }
event_id: { type: String },
infoevent: { type: String }
},
origin: {
username: { type: String },
type: String,
},
dest: {
idapp: { type: String, },
username: { type: String },
type: String,
},
message: {
type: String,
@@ -54,7 +54,7 @@ sendmsgSchema.statics.findAllMsgByUsernameIdAndIdApp = function (username, lastd
return SendMsg.find({
$and: [
{ $or: [ { 'dest.username': username }, { 'origin.username': username },] },
{ $or: [ { 'dest': username }, { 'origin': username },] },
{ 'datemsg': {$gt: new Date(lastdataread)} },
{ idapp }
]
@@ -73,14 +73,14 @@ sendmsgSchema.statics.findLastGroupByUserIdAndIdApp = function (userId, username
return SendMsg.aggregate([
{
$match: {
$or: [{ 'origin.username': username }, { 'dest.username': username }, { idapp }],
$or: [{ 'origin': username }, { 'dest': username }, { idapp }],
$and: [{ idapp }]
}
},
{
$group:
{
_id: "$dest.username",
_id: "$dest",
message: { $last: "$message" },
datemsg: { $last: "$datemsg" },
dest: { $last: "$dest" },

View File

@@ -194,7 +194,28 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYHOSPS, true) + myidrec;
tag = 'newhosp';
}
recnotif.textaddTelegram = 'Vedi post';
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_EVENTS) {
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYBACHECAS, true) + myidrec;
tag = 'newevent';
if (recnotif.typeid === shared_consts.TypeNotifs.ID_EVENTS_NEW_REC) {
newdescr = i18n.__('NEW_EVENT', userorig, mydescr);
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_EVENTS_SEND_MSG) {
newdescr = i18n.__('EVENT_SEND_MSG', userorig, recnotif.title, recnotif.msg);
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_EVENTS_ATTEND) {
// ++ Controlla se esiste già
let esitegia = recnotif.paramsObj.recObjCreator.exist; // ++
if (esitegia)
newdescr = i18n.__('SET_ATTEND_OTHERS', recnotif.paramsObj.username_action, recnotif.paramsObj.recObjCreator.numattend - 1, recnotif.paramsObj.recObjCreator.descr);
else
newdescr = i18n.__('SET_ATTEND', recnotif.paramsObj.username_action, recnotif.paramsObj.recObjCreator.descr);
tag = 'attend';
recnotif.openUrl = shared_consts.getDirectoryByTable(recnotif.paramsObj.recObjCreator.table, true) + recnotif.paramsObj.recObjCreator.id;
recnotif.textaddTelegram = 'Vedi post';
}
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FRIENDS) {
recnotif.openUrl = '/my/' + sender;
if (recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_NEW_REC) {
@@ -562,7 +583,10 @@ sendNotifSchema.statics.saveAndSendNotif = async function (myrecnotif, req, res,
const myrecread = await SendNotif.findById(idobj).lean();
// console.log('myrecread._id', myrecread._id.toString());
return await globalTables.sendNotif(myrecread.typedir, myrecread.typeid, res, idapp, user ? user : req.user, myrecread);
if (myrecread)
return await globalTables.sendNotif(myrecread.typedir, myrecread.typeid, res, idapp, user ? user : req.user, myrecread);
else
return false;
}
} catch (e) {
@@ -666,8 +690,6 @@ sendNotifSchema.statics.updateStatusAndDescr = async function (myrecnotif, onlys
newstatus = shared_consts.CircuitsNotif.STATUS_COINS_REFUSED_SENT;
}
} else if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FAVORITE) {
// typeidsearch = shared_consts.TypeNotifs.ID_FAVORITE_ADDED;
}
if (newstatus) {
@@ -934,6 +956,13 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
let send = false;
if (myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_EVENTS) {
if (myrecnotifpass.tablerec === shared_consts.TABLES_MYBACHECAS) {
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.TypeNotifs.ID_EVENTS_ATTEND)) {
send = true;
}
}
}
if (myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_FAVORITE) {
if (shared_consts.TABLES_FAVORITE_BOOKMARK.includes(myrecnotifpass.tablerec)) {
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.TypeNotifs.ID_FAVORITE_ADDED)) {

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;