no message
This commit is contained in:
@@ -5,7 +5,7 @@ const Mongoose = require('mongoose');
|
|||||||
const MessageSchema = new Mongoose.Schema({
|
const MessageSchema = new Mongoose.Schema({
|
||||||
"order" : { type: Number, default: 0 },
|
"order" : { type: Number, default: 0 },
|
||||||
"text" : { type: String },
|
"text" : { type: String },
|
||||||
"image" : { type: String },
|
"image" : { type: String, index: true },
|
||||||
"isUser" : { type: Boolean, default: false, required: true, 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) => {
|
create: (e, profiles) => {
|
||||||
var count = profiles.length;
|
var count = profiles.length;
|
||||||
var errors = [];
|
var errors = [];
|
||||||
|
|||||||
@@ -154,7 +154,25 @@ Router.route('/list' + ParamStr)
|
|||||||
Profiles.find(ProfileEvents, query);
|
Profiles.find(ProfileEvents, query);
|
||||||
});
|
});
|
||||||
|
|
||||||
Router.route('/:profileId?/messages/:messageId?')
|
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?')
|
||||||
.delete((req, res) => {
|
.delete((req, res) => {
|
||||||
var ProfileEvents = new EventEmitter();
|
var ProfileEvents = new EventEmitter();
|
||||||
var profileId = req.params.profileId || null;
|
var profileId = req.params.profileId || null;
|
||||||
|
|||||||
Reference in New Issue
Block a user