no message
This commit is contained in:
@@ -5,7 +5,7 @@ const Mongoose = require('mongoose');
|
||||
const MessageSchema = new Mongoose.Schema({
|
||||
"order" : { type: Number, default: 0 },
|
||||
"text" : { type: String },
|
||||
"image" : { type: String },
|
||||
"image" : { type: String, index: true },
|
||||
"isUser" : { type: Boolean, default: false, required: true, index: true }
|
||||
});
|
||||
|
||||
|
||||
@@ -163,6 +163,30 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
allMessageImages: (e, profileId) => {
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
ProfileModel
|
||||
.find({ _id: prodileId, 'messages.image': { $exists: true } })
|
||||
.select('image')
|
||||
.exec((err, result) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
|
||||
if (result) {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
promise.then((result) => {
|
||||
e.emit('allMessageImages', null, result);
|
||||
})
|
||||
.catch((err) => {
|
||||
e.emit('allMessageImages', err, null);
|
||||
});
|
||||
},
|
||||
|
||||
create: (e, profiles) => {
|
||||
var count = profiles.length;
|
||||
var errors = [];
|
||||
@@ -340,7 +364,7 @@ module.exports = {
|
||||
e.emit('getMessage', err, null);
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
update: (e, id, profile) => {
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
ProfileModel.findOneAndUpdate(
|
||||
|
||||
@@ -153,8 +153,26 @@ Router.route('/list' + ParamStr)
|
||||
|
||||
Profiles.find(ProfileEvents, query);
|
||||
});
|
||||
|
||||
Router.route('/:profileId/messages/images')
|
||||
.get((req, res) => {
|
||||
var ProfileEvents = new EventEmitter();
|
||||
var profileId = req.params.profileId;
|
||||
|
||||
ProfileEvents.once('allMessageImages', (err, result) => {
|
||||
if (err) {
|
||||
res.status(500).json({ message: 'Could not get chat images' + (messageId ? ' ' : 's ') + 'for profile' + (profileId ? '' : 's') + ' [' + err + ']', err: err });
|
||||
}
|
||||
|
||||
if (result) {
|
||||
res.status(200).json(result);
|
||||
}
|
||||
});
|
||||
|
||||
Profiles.allMessageImages(ProfileEvents, profileId);
|
||||
});
|
||||
|
||||
Router.route('/:profileId?/messages/:messageId?')
|
||||
Router.route('/:profileId/messages/:messageId?')
|
||||
.delete((req, res) => {
|
||||
var ProfileEvents = new EventEmitter();
|
||||
var profileId = req.params.profileId || null;
|
||||
|
||||
Reference in New Issue
Block a user