Step 1: Creating page Messages: userlist last messages + a page for all the messages received and sent.
This commit is contained in:
@@ -15,11 +15,13 @@ const sendmsgSchema = new Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
},
|
||||
origin: {
|
||||
userId: { type: String },
|
||||
source: {
|
||||
page: { type: String },
|
||||
event_id: { type: String }
|
||||
},
|
||||
origin: {
|
||||
username: { type: String },
|
||||
},
|
||||
dest: {
|
||||
idapp: { type: String, },
|
||||
username: { type: String },
|
||||
@@ -41,20 +43,20 @@ const sendmsgSchema = new Schema({
|
||||
|
||||
});
|
||||
|
||||
sendmsgSchema.statics.findAllByUserIdAndIdApp = function (userId, username, idapp) {
|
||||
sendmsgSchema.statics.findAllMsgByUsernameIdAndIdApp = function (username, lastdataread, idapp) {
|
||||
const SendMsg = this;
|
||||
|
||||
return SendMsg.find({
|
||||
$and: [
|
||||
{
|
||||
$or: [
|
||||
{ 'origin.userId': userId },
|
||||
{ 'dest.username': username }]
|
||||
},
|
||||
{ $or: [ { 'dest.username': username }, { 'origin.username': username },] },
|
||||
{ 'datemsg': {$gt: new Date(lastdataread)} },
|
||||
{ idapp }
|
||||
]
|
||||
}, (err, arrmsg) => {
|
||||
}).then((arrmsg) => {
|
||||
console.log('arrmsg', arrmsg);
|
||||
return arrmsg
|
||||
}).catch((err) => {
|
||||
console.error('err', err);
|
||||
});
|
||||
|
||||
};
|
||||
@@ -65,7 +67,7 @@ sendmsgSchema.statics.findLastGroupByUserIdAndIdApp = function (userId, username
|
||||
return SendMsg.aggregate([
|
||||
{
|
||||
$match: {
|
||||
$or: [{ 'origin.userId': userId }, { 'dest.username': username }, { idapp }],
|
||||
$or: [{ 'origin.username': username }, { 'dest.username': username }, { idapp }],
|
||||
$and: [{ idapp }]
|
||||
}
|
||||
},
|
||||
@@ -74,7 +76,6 @@ sendmsgSchema.statics.findLastGroupByUserIdAndIdApp = function (userId, username
|
||||
{
|
||||
_id: "$dest.username",
|
||||
message: { $last: "$message" },
|
||||
|
||||
datemsg: { $last: "$datemsg" },
|
||||
dest: { $last: "$dest" },
|
||||
origin: { $last: "$origin" },
|
||||
|
||||
@@ -318,7 +318,7 @@ router.get('/loadsite/:userId/:idapp/:sall', authenticate_noerror, (req, res) =>
|
||||
const wheres = Where.findAllIdApp(idapp);
|
||||
const contribtype = Contribtype.findAllIdApp(idapp);
|
||||
|
||||
return Promise.all([bookedevent, eventlist, operators, wheres, contribtype, msgs])
|
||||
return Promise.all([bookedevent, eventlist, operators, wheres, contribtype])
|
||||
.then((arrdata) => {
|
||||
// console.table(arrdata);
|
||||
res.send({
|
||||
@@ -355,7 +355,7 @@ 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.findLastGroupByUserIdAndIdApp(userId, req.user.username, req.user.idapp);
|
||||
last_msgs = SendMsg.findLastGroupByUserIdAndIdApp(userId, req.user.username, req.user.idapp);
|
||||
|
||||
|
||||
let usersList = null;
|
||||
@@ -368,13 +368,13 @@ router.get(process.env.LINK_CHECK_UPDATES, authenticate, (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.all([usersList, msgs])
|
||||
return Promise.all([usersList, last_msgs])
|
||||
.then((arrdata) => {
|
||||
// console.table(arrdata);
|
||||
return res.send({
|
||||
cfgServer: arrcfgrec,
|
||||
usersList: arrdata[0],
|
||||
msgs: arrdata[1],
|
||||
last_msgs: arrdata[1],
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -67,25 +67,23 @@ router.post('/', authenticate, (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.get('/:userId/:idapp', authenticate, (req, res) => {
|
||||
const userId = req.params.userId;
|
||||
router.get('/:username/:lastdataread/:idapp', authenticate, (req, res) => {
|
||||
const username = req.params.username;
|
||||
const lastdataread = req.params.lastdataread;
|
||||
const idapp = req.params.idapp;
|
||||
// var category = req.params.category;
|
||||
|
||||
tools.mylog('GET SendMsgS : ', req.params);
|
||||
|
||||
if (!ObjectID.isValid(userId)) {
|
||||
return res.status(404).send();
|
||||
}
|
||||
|
||||
if (userId !== String(req.user._id)) {
|
||||
// I'm trying to write something not mine!
|
||||
return res.status(404).send({ code: server_constants.RIS_CODE_TODO_CREATING_NOTMYUSER });
|
||||
if (req.user.idapp !== idapp) {
|
||||
// I'm trying to get something not mine!
|
||||
return res.status(404).send({ code: server_constants.RIS_CODE_NOT_MY_USERNAME });
|
||||
}
|
||||
|
||||
// Extract all the todos of the userId only
|
||||
return SendMsg.findAllByUserIdAndIdApp(userId, idapp).then((msgall) => {
|
||||
res.send({ msgall });
|
||||
return SendMsg.findAllMsgByUsernameIdAndIdApp(username, lastdataread, idapp).then((arrmsg) => {
|
||||
|
||||
res.send({ arrmsg });
|
||||
}).catch((e) => {
|
||||
console.log(e);
|
||||
res.status(400).send(e);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
module.exports = Object.freeze({
|
||||
RIS_CODE_TODO_CREATING_NOTMYUSER: -1001,
|
||||
RIS_CODE_NOT_MY_USERNAME: -1010,
|
||||
|
||||
RIS_CODE_ERR: -99,
|
||||
RIS_CODE_EMAIL_ALREADY_VERIFIED: -5,
|
||||
|
||||
Reference in New Issue
Block a user