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

@@ -679,7 +679,9 @@ module.exports = {
return [
'idapp',
'userId',
'username',
'id_bookedevent',
'tableType',
'numpeople',
'numpeopleLunch',
'numpeopleDinner',
@@ -1455,8 +1457,9 @@ module.exports = {
} else {
return {
exit: true,
ret: res.status(404).
send({ code: server_constants.RIS_CODE_TODO_CREATING_NOTMYUSER }),
ret: false,
// ret: res.status(404).
// send({ code: server_constants.RIS_CODE_TODO_CREATING_NOTMYUSER }),
};
}
} else {
@@ -1836,18 +1839,33 @@ module.exports = {
foreignField: params.lk_FF, // field in the 'from' collection
as: params.lk_as,
},
},
{
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
$arrayElemAt: [
'$' + params.lk_as, 0],
}, '$$ROOT'],
});
if (params.unwind) {
query.push({
$unwind: {
path: '$' + params.lk_as,
preserveNullAndEmptyArrays: true,
}
})
}
if (!params.noarray) {
query.push(
{
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
$arrayElemAt: [
'$' + params.lk_as, 0],
}, '$$ROOT'],
},
},
},
},
});
}
query.push(
{ $project: proj },
);
}
@@ -2012,21 +2030,148 @@ module.exports = {
as: 'myseen',
},
},
];
{
$lookup: {
from: "users",
let: {
tab: numtab,
id: '$_id',
},
pipeline: [
{
$unwind: '$profile.attend',
},
{
$match: {
$expr: {
$and: [
{ $eq: ['$profile.attend.id', '$$id'] },
{ $eq: ['$profile.attend.tab', '$$tab'] },
{ $eq: ['$idapp', idapp] },
],
},
},
},
{
$project: {
username: 1, name: 1, surname: 1, 'profile.resid_province': 1, 'profile.img': 1,
'profile.qualifica': 1,
}
},
],
as: 'myattend',
},
}];
const numtabbacheca = this.getNumTabByTable(shared_consts.TABLES_MYBACHECAS);
if (numtab === numtabbacheca) {
const queryadd = this.getQueryMyBacheca();
query = [...query, ...queryadd];
}
proj = {
myfav: 1,
mybook: 1,
myseen: 1,
myattend: 1,
mybookings: 1,
};
return { query, proj };
},
getQueryMyBacheca: function () {
const arrquery = [{
$lookup: {
from: "bookings",
let: {
id: '$_id',
},
pipeline: [
{
$match: {
$expr: {
$and: [
{ $eq: ['$id_bookedevent', '$$id'] },
{ $eq: ['$idapp', idapp] },
],
},
},
},
{
$project: {
id_bookedevent: 1,
username: 1,
numpeople: 1,
numpeopleLunch: 1,
numpeopleDinner: 1,
infoevent: 1,
msgbooking: 1,
booked: 1,
datebooked: 1,
userId: 1,
}
},
],
as: 'mybookings',
},
},
/**
{
$lookup: {
from: "users",
localField: "myId1",
foreignField: "_id",
as: "user",
},
},
{
$lookup: {
from: "users",
let: {
myid: { $toObjectId: "$mybookings.userId" },
},
pipeline: [
{
$match: {
$expr: {
$and: [
{
$eq: [
"$_id",
"$$myid",
],
},
{
$eq: [
"$idapp",
"13",
],
},
],
},
},
},
{
$project: { _id: 1, username: 1 },
}
],
as: "myuser",
},
}**/
];
return arrquery;
},
getQueryTable: async function (idapp, params, user) {
const { Search }= require('../models/search');
const { Search } = require('../models/search');
if (typeof params.startRow !== 'number') {
throw new Error('startRow must be number');
@@ -2610,7 +2755,7 @@ module.exports = {
// Save the search:
if (user._id) {
const mysearch = new Search({idapp, userId: user._id, text: params.filter});
const mysearch = new Search({ idapp, userId: user._id, text: params.filter });
await mysearch.save();
}
}
@@ -3875,7 +4020,7 @@ module.exports = {
},
updateQueryStringParameter(uri, key, value) {
if (uri === '')
if (uri === '' || !uri)
return '';
var re = new RegExp('([?&])' + key + '=.*?(&|$)', 'i');
var separator = uri.indexOf('?') !== -1 ? '&' : '?';

View File

@@ -387,9 +387,9 @@ module.exports = {
let sendmsg = false;
if (params.typenotif === shared_consts.TypeNotifs.TYPEDIR_FAVORITE) {
if (!usernotifprofile || (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.TypeNotifs.ID_FAVORITE_ADDED))) {
sendmsg = true;
}
if (!usernotifprofile || (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.TypeNotifs.ID_FAVORITE_ADDED))) {
sendmsg = true;
}
} else {
sendmsg = true;
}
@@ -592,6 +592,50 @@ module.exports = {
},
getNumAttendByIdObj: async function (idapp, numtab, id) {
const { User } = require('../models/user');
let query = [
{
$match: {
idapp,
"profile.attend": {
$elemMatch:
{ id, tab: numtab }
}
},
},
{
$group:
{
_id: null,
count: {
$sum:
{
$reduce: {
input: "$profile.attend",
initialValue: 0,
in: {
$add: ["$$value", "$$this.num"]
}
}
}
},
}
},
{ $project: { _id: 0 } }
];
try {
const [result] = await User.aggregate(query);
return result ? result.count : 0;
} catch (err) {
return 0;
}
},
getUserCreatorByNumTabAndId: async function (idapp, id, numtab) {
try {
const table = tools.getTableByNumTab(numtab);
@@ -604,10 +648,15 @@ module.exports = {
if (rec) {
const recuser = await User.getUserById(idapp, rec.userId);
let numattend = await this.getNumAttendByIdObj(idapp, numtab, id);
let numfav = await this.getNumFavoriteByIdObj(idapp, numtab, id);
let exist = numfav > 1;
let exist = false;
if (table === shared_consts.TABLES_MYBACHECAS)
exist = numattend > 1;
else
exist = numfav > 1;
if (recuser)
return { userId: rec.userId, username: recuser.username, descr: rec.descr, id: rec._id, table, exist, numfav };
return { userId: rec.userId, username: recuser.username, descr: rec.descr, id: rec._id, table, exist, numfav, numattend };
}
}
} catch (e) {

View File

@@ -138,18 +138,21 @@ module.exports = {
TABLES_MYHOSPS: 'myhosps',
TABLES_MYGOODS: 'mygoods',
TABLES_MYEVENTS: 'myevents',
TABLES_CIRCUITS: 'circuits',
TABLES_MYGROUPS: 'mygroups',
MYTABS: [{id: 0, table: 'none' },
{id: 1, table: 'myskills'},
{id: 2, table: 'mybachecas' },
{id: 3, table: 'myhosps'} ,
{id: 4, table: 'mygoods'},
{id: 5, table: 'myevents'}],
MYTABS: [{ id: 0, table: 'none' },
{ id: 1, table: 'myskills' },
{ id: 2, table: 'mybachecas' },
{ id: 3, table: 'myhosps' },
{ id: 4, table: 'mygoods' },
{ id: 5, table: 'myevents' }],
CMD_USER: {
SET_FAVORITE: 1,
SET_BOOKMARK: 2,
SET_SEEN: 3,
SET_ATTEND: 4,
},
TABLES_ENABLE_GETREC_BYID: ['mybachecas', 'myhosps', 'myskills', 'mygoods'],
@@ -171,13 +174,13 @@ module.exports = {
TABLES_GROUPS_NOTIFICATION: ['mygroups'],
TABLES_CIRCUITS_NOTIFICATION: ['circuits'],
TABLES_NUM_AS_ID_NUMBER: [ ],
TABLES_NUM_AS_ID_NUMBER: [],
TABLES_ID_STRING: [
'circuits',
'accounts',
'movements',
],
'circuits',
'accounts',
'movements',
],
TABLES_ID_NUMBER: [
'permissions',
@@ -212,19 +215,19 @@ module.exports = {
table: 'adtypes',
key: 'descr',
},
{table: 'catgrps', key: 'descr'},
{ table: 'catgrps', key: 'descr' },
{
table: 'contribtypes',
key: 'descr',
},
{table: 'goods', key: 'descr'},
{table: 'levels', key: 'descr'},
{table: 'cities', key: 'comune'},
{table: 'provinces', key: 'descr'},
{table: 'sectorgoods', key: 'descr'},
{table: 'sectors', key: 'descr'},
{table: 'skills', key: 'descr'},
{table: 'statusSkills', key: 'descr'},
{ table: 'goods', key: 'descr' },
{ table: 'levels', key: 'descr' },
{ table: 'cities', key: 'comune' },
{ table: 'provinces', key: 'descr' },
{ table: 'sectorgoods', key: 'descr' },
{ table: 'sectors', key: 'descr' },
{ table: 'skills', key: 'descr' },
{ table: 'statusSkills', key: 'descr' },
],
VISIB_ALL: 0,
@@ -411,6 +414,8 @@ module.exports = {
TYPEDIR_EVENTS: 2,
ID_EVENTS_NEW_REC: 1,
ID_EVENTS_REMOVE_REC: 2,
ID_EVENTS_ATTEND: 4,
ID_EVENTS_SEND_MSG: 8,
TYPEDIR_FRIENDS: 3,
ID_FRIENDS_NEW_REC: 1,
@@ -464,7 +469,7 @@ module.exports = {
},
// Tipi di Notifiche:
// Tipi di Notifiche:
/*
Notif: {
UPDATE_APP: 1,
@@ -520,7 +525,7 @@ module.exports = {
},
{
'dir': 2,
'value': 1
'value': 4
},
{
'dir': 3,
@@ -538,6 +543,10 @@ module.exports = {
'dir': 11,
'value': 1
},
{
'dir': 12,
'value': 1
},
],
CIRCUIT_STATUS: {
@@ -554,7 +563,149 @@ module.exports = {
SCOPERTO_MAX_CONTO_COMUNITARIO: 1000,
},
getProjectForAll(proj_add) {
TABLETYPE: {
DefaultCal: 0,
MyBachecas: 1,
},
getProjectByTable(table, proj_add) {
let proj = {}
if (table === this.TABLES_MYGOODS) {
proj = {
'recGood': 1,
'sectorGood': 1,
'idSectorGood': 1,
'idGood': 1,
'idShipping': 1,
'idStatusGood': 1,
//**ADDFIELD_MYGOOD
}
} else if (table === this.TABLES_MYGROUPS) {
proj = {
groupname: 1,
title: 1,
descr: 1,
img: 1,
visibility: 1,
admins: 1,
idCatGrp: 1,
date_created: 1,
date_updated: 1,
photos: 1,
idCity: 1,
note: 1,
website: 1,
link_telegram: 1,
comune: 1,
mycities: 1,
sector: 1,
recCatGrp: 1,
}
} else if (table === this.TABLES_CIRCUITS) {
proj = {
_id: 1,
groupnameId: 1,
path: 1,
name: 1,
strProv: 1,
subname: 1,
longdescr: 1,
regulation: 1,
numMembers: 1,
totCircolante: 1,
totTransato: 1,
systemUserId: 1,
createdBy: 1,
date_created: 1,
date_updated: 1,
nome_valuta: 1,
fido_scoperto_default: 1,
deperimento: 1,
status: 1,
transactionsEnabled: 1,
qta_max_default: 1,
fido_scoperto_default_grp: 1,
qta_max_default_grp: 1,
valuta_per_euro: 1,
symbol: 1,
idCity: 1,
pub_to_share: 1,
visibility: 1,
color: 1,
abbrev: 1,
data_costituz: 1,
photos: 1,
admins: 1,
req_users: 1,
refused_users: 1,
'mycities': 1,
//**ADDFIELD_CIRCUITS
}
} else if (table === this.TABLES_MYSKILLS) {
proj = {
recSkill: 1,
sector: 1,
idSector: 1,
idSkill: 1,
myskill: 1,
idStatusSkill: 1,
idContribType: 1,
numLevel: 1,
adType: 1,
photos: 1,
note: 1,
website: 1,
//**ADDFIELD_MYSKILL
}
} else if (table === this.TABLES_MYHOSPS) {
proj = {
visibile: 1,
typeHosp: 1,
numMaxPeopleHosp: 1,
accomodation: 1,
preferences: 1,
idContribType: 1,
photos: 1,
idCity: 1,
note: 1,
website: 1,
link_maplocation: 1,
}
} else if (table === this.TABLES_MYBACHECAS) {
proj = {
recSkill: 1,
sector: 1,
idSector: 1,
idSkill: 1,
// 'idSubSkill': 1,
idStatusSkill: 1,
idContribType: 1,
dateTimeStart: 1,
dateTimeEnd: 1,
website: 1,
organisedBy: 1,
contact_phone: 1,
contact_telegram: 1,
address: 1,
min_partecip: 1,
max_partecip: 1,
contribstr: 1,
link_maplocation: 1,
//**ADDFIELD_MYBACHECAS
}
}
if (proj_add)
proj = Object.assign({}, proj, proj_add);
return proj;
},
getProjectForAll(proj_add, table) {
let proj = {
idContribType: 1,
idCity: 1,
@@ -580,6 +731,7 @@ module.exports = {
'profile.username_telegram': 1,
'profile.favorite': 1,
'profile.bookmark': 1,
'profile.attend': 1,
'profile.seen': 1,
reported: 1,
date_report: 1,
@@ -591,6 +743,11 @@ module.exports = {
if (proj_add)
proj = Object.assign({}, proj, proj_add);
if (table) {
let proj_add3 = this.getProjectByTable(table);
proj = Object.assign({}, proj, proj_add3);
}
return proj;
},