aggiunto "Seen"

This commit is contained in:
Surya Paolo
2023-04-13 14:27:00 +02:00
parent cda0bff21f
commit eea6e63c58
5 changed files with 60 additions and 0 deletions

View File

@@ -282,6 +282,7 @@ let aggregation = [
username_who_report: 1,
myfav: 1,
mybook: 1,
myseen: 1,
},
},
{

View File

@@ -452,6 +452,13 @@ const UserSchema = new mongoose.Schema({
noFoto: {
type: Boolean,
},
seen: [
{
_id: false,
id: { type: String },
tab: { type: Number },
},
],
bookmark: [
{
_id: false,
@@ -1607,6 +1614,7 @@ UserSchema.statics.getUserProfileByUsername = async function (
'profile.friends': 1,
'profile.favorite': 1,
'profile.bookmark': 1,
'profile.seen': 1,
email: 1,
date_reg: 1,
'useraport.username': 1,
@@ -1653,6 +1661,7 @@ UserSchema.statics.getUserProfileByUsername = async function (
'profile.friends': 1,
'profile.favorite': 1,
'profile.bookmark': 1,
'profile.seen': 1,
email: 1,
date_reg: 1,
'useraport.username': 1,
@@ -1700,6 +1709,7 @@ UserSchema.statics.getUserProfileByUsername = async function (
'profile.friends': 1,
'profile.favorite': 1,
'profile.bookmark': 1,
'profile.seen': 1,
'mycities': 1,
'comune': 1,
email: 1,
@@ -1946,6 +1956,12 @@ UserSchema.statics.addBookmark = async function (
return await User.updateOne({ idapp, username },
{ $push: { 'profile.bookmark': { id, tab } } });
};
// Aggiungo il Bookmark
UserSchema.statics.addSeen = async function (
idapp, username, id, tab) {
return await User.updateOne({ idapp, username },
{ $push: { 'profile.seen': { id, tab } } });
};
UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, usernameDest, cmd, value, disablenotif) {
@@ -2800,6 +2816,7 @@ function getWhatToShow(idapp, username) {
'profile.handshake': 1,
'profile.favorite': 1,
'profile.bookmark': 1,
'profile.seen': 1,
};
}
@@ -2825,6 +2842,7 @@ function getWhatToShow_Unknown(idapp, username) {
'profile.friends': 1,
'profile.favorite': 1,
'profile.bookmark': 1,
'profile.seen': 1,
}
}
@@ -2853,6 +2871,7 @@ UserSchema.statics.getWhatToShow_IfFriends = async function (idapp, username) {
'profile.friends': 1,
'profile.favorite': 1,
'profile.bookmark': 1,
'profile.seen': 1,
};
};

View File

@@ -1568,6 +1568,11 @@ router.post('/cmd', authenticate, async (req, res) => {
else
ris = await User.removeBookmark(idapp, username, id, tab);
}
} else if (cmd === shared_consts.CMD_USER.SET_SEEN) {
if (tab) {
if (value)
ris = await User.addSeen(idapp, username, id, tab);
}
}
let state = (value && ris && ris.ok === 1) ? 1 : ((!value && ris && ris.ok === 1) ? -1 : 0);

View File

@@ -1980,11 +1980,44 @@ module.exports = {
as: 'mybook',
},
},
{
$lookup: {
from: "users",
let: {
tab: numtab,
id: '$_id',
},
pipeline: [
{
$unwind: '$profile.seen',
},
{
$match: {
$expr: {
$and: [
{ $eq: ['$profile.seen.id', '$$id'] },
{ $eq: ['$profile.seen.tab', '$$tab'] },
{ $eq: ['$idapp', idapp] },
],
},
},
},
{
$project: {
username: 1, name: 1, surname: 1, 'profile.resid_province': 1, 'profile.img': 1,
'profile.qualifica': 1,
}
},
],
as: 'myseen',
},
},
];
proj = {
myfav: 1,
mybook: 1,
myseen: 1,
};
return { query, proj };

View File

@@ -149,6 +149,7 @@ module.exports = {
CMD_USER: {
SET_FAVORITE: 1,
SET_BOOKMARK: 2,
SET_SEEN: 3,
},
TABLES_ENABLE_GETREC_BYID: ['mybachecas', 'myhosps', 'myskills', 'mygoods'],
@@ -579,6 +580,7 @@ module.exports = {
'profile.username_telegram': 1,
'profile.favorite': 1,
'profile.bookmark': 1,
'profile.seen': 1,
reported: 1,
date_report: 1,
username_who_report: 1,