- Fixed Image avatar user list, q-qvatar rounded image

This commit is contained in:
Paolo Arena
2019-10-25 19:08:38 +02:00
parent c8c4f57d16
commit 4154605fdd
6 changed files with 56 additions and 40 deletions

View File

@@ -44,12 +44,6 @@ const sendmsgSchema = new Schema({
sendmsgSchema.statics.findAllByUserIdAndIdApp = function (userId, username, idapp) {
const SendMsg = this;
// Filter my msg
//
// (userId or dest.username === username) and idapp
console.log('userId', userId);
return SendMsg.find({
$and: [
{
@@ -60,27 +54,44 @@ sendmsgSchema.statics.findAllByUserIdAndIdApp = function (userId, username, idap
{ idapp }
]
}, (err, arrmsg) => {
// console.log('ris arrmsg:', arrmsg);
return arrmsg
});
// return SendMsg.find(
// {
// $and: [
// {
// $or: [
// { 'dest.username': username },
// { userId: userId }
// ],
// },
// {
// idapp
// }
// ]
// }, (err, arrmsg) => {
// console.log('ris arrmsg:', arrmsg);
// return arrmsg
// });
};
sendmsgSchema.statics.findLastGroupByUserIdAndIdApp = function (userId, username, idapp) {
const SendMsg = this;
return SendMsg.aggregate([
{
$match: {
$or: [{ 'origin.userId': userId }, { 'dest.username': username }, { idapp }],
$and: [{ idapp }]
}
},
{
$group:
{
_id: "$dest.username",
message: { $last: "$message" },
datemsg: { $last: "$datemsg" },
dest: { $last: "$dest" },
origin: { $last: "$origin" },
read: { $last: "$read" }
}
},
{
$sort: { datemsg: -1 }
},
])
.then((arrmsg) => {
console.table(arrmsg);
return arrmsg
}).catch((err) => {
console.error(err);
});
};

View File

@@ -89,6 +89,9 @@ var UserSchema = new mongoose.Schema({
perm: {
type: Number
},
img: {
type: String
},
ipaddr: {
type: String,
},
@@ -109,7 +112,7 @@ UserSchema.methods.toJSON = function () {
var user = this;
var userObject = user.toObject();
return _.pick(userObject, ['_id', 'email', 'verified_email', 'idapp', 'username', 'userId', 'name', 'surname', 'perm']);
return _.pick(userObject, ['_id', ...shared_consts.fieldsUserToChange()]);
};
UserSchema.methods.generateAuthToken = function (req) {
@@ -306,7 +309,7 @@ UserSchema.methods.removeToken = function (token) {
UserSchema.statics.getUsersList = function (idapp) {
const User = this;
return User.find({ 'idapp': idapp }, { username: 1, name: 1, surname: 1, verified_email: 1, perm:1, email: 1, date_reg: 1 })
return User.find({ 'idapp': idapp }, { username: 1, name: 1, surname: 1, verified_email: 1, perm:1, email: 1, date_reg: 1, img: 1 })
};
@@ -321,7 +324,7 @@ UserSchema.statics.getUsersListByParams = function (params) {
return User.find(
{ $match: filterMatchBefore },
{ 'idapp': idapp },
{ username: 1, name: 1, surname: 1, verified_email: 1, perm:1, email: 1, date_reg: 1 })
{ username: 1, name: 1, surname: 1, verified_email: 1, perm:1, email: 1, date_reg: 1, img: 1 })
};

View File

@@ -354,7 +354,9 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate, (req, res) => {
// const sall = '0';
msgs = SendMsg.findAllByUserIdAndIdApp(userId, req.user.username, req.user.idapp);
// msgs = SendMsg.findAllByUserIdAndIdApp(userId, req.user.username, req.user.idapp);
msgs = SendMsg.findLastGroupByUserIdAndIdApp(userId, req.user.username, req.user.idapp);
let usersList = null;

View File

@@ -145,10 +145,11 @@ router.post('/login', (req, res) => {
usertosend.name = user.name;
usertosend.surname = user.surname;
usertosend.email = user.email;
usertosend.userId = user._id.toHexString();
usertosend._id = user._id.toHexString();
usertosend.verified_email = user.verified_email;
usertosend.idapp = user.idapp;
usertosend.perm = user.perm;
usertosend.img = user.img;
if (!User.isAdmin(req.user)) {
usertosend.ipaddr = user.ipaddr;
}
@@ -166,7 +167,7 @@ router.post('/login', (req, res) => {
const browser = req.get('User-Agent');
// Check if already exist Subscribe
return existSubScribe(myris.usertosend.userId, access, browser).then(subscribe => {
return existSubScribe(myris.usertosend._id, access, browser).then(subscribe => {
return (subscribe !== null)
}).then(subsExistonDb => {
return { usertosend: myris.usertosend, token: myris.token, subsExistonDb }

View File

@@ -125,7 +125,6 @@ const todos = [{
pos: 3,
priority: 1,
progress: 0,
userId: users[1]._id
}, { // RECORD CHE VERRA' UTILIZZATO PER AGGIUNGERE UN NUOVO TASK
_id: new ObjectID(),
category: "personal",

View File

@@ -7,7 +7,7 @@ module.exports = {
},
fieldsUserToChange() {
return ['username', 'email', 'name', 'surname', 'perm', 'date_reg', 'verified_email']
return ['username', 'email', 'name', 'surname', 'perm', 'date_reg', 'verified_email', 'img', 'ipaddr']
}
};