Files
freeplanet_serverside/server/models/sendmsg.js
Paolo Arena c8c4f57d16 - Delete Event with ask confirmation
- Fix dateStart only 1 view if is the same day
- Sending a message from the Event Page: to a user or to a "Event"
- Add button "Ask Info"
- Starting view msg into the messagepopup component
2019-10-24 23:30:45 +02:00

90 lines
1.6 KiB
JavaScript

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
mongoose.level = "F";
const { ObjectID } = require('mongodb');
// Resolving error Unknown modifier: $pushAll
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
const sendmsgSchema = new Schema({
idapp: {
type: String,
},
origin: {
userId: { type: String },
page: { type: String },
event_id: { type: String }
},
dest: {
idapp: { type: String, },
username: { type: String },
},
message: {
type: String,
},
datemsg: {
type: Date,
},
read: {
type: Boolean,
default: false
},
deleted: {
type: Boolean,
default: false
},
});
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: [
{
$or: [
{ 'origin.userId': userId },
{ 'dest.username': username }]
},
{ 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
// });
};
const SendMsg = mongoose.model('SendMsg', sendmsgSchema);
module.exports = { SendMsg };