no message
This commit is contained in:
@@ -3,10 +3,10 @@ const Logger = require('../modules/logger');
|
|||||||
const Mongoose = require('mongoose');
|
const Mongoose = require('mongoose');
|
||||||
|
|
||||||
const MessageSchema = new Mongoose.Schema({
|
const MessageSchema = new Mongoose.Schema({
|
||||||
"order" : { type: Number, default: 0 },
|
|
||||||
"text" : { type: String },
|
"text" : { type: String },
|
||||||
"image" : { type: String, index: true },
|
"image" : { type: String, index: true },
|
||||||
"isUser" : { type: Boolean, default: false, required: true, index: true }
|
"isUser" : { type: Boolean, default: false, required: true, index: true },
|
||||||
|
"timestamp": { type: Date, default: Date.now() }
|
||||||
});
|
});
|
||||||
|
|
||||||
MessageSchema.pre('findOneAndUpdate', function (next) {
|
MessageSchema.pre('findOneAndUpdate', function (next) {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ const ProfileSchema = new Mongoose.Schema({
|
|||||||
"weight": { type: Number },
|
"weight": { type: Number },
|
||||||
"status": [{ type: String, enum: ['unknown','negative','negative, on prep','postive','positive, undetectable'] }],
|
"status": [{ type: String, enum: ['unknown','negative','negative, on prep','postive','positive, undetectable'] }],
|
||||||
"tested": { type: Date },
|
"tested": { type: Date },
|
||||||
"tribe": [{ type: String, enum: [] }]
|
"tribe": [{ type: String, enum: ['twink','geek','otter','bear','daddy','jock'] }]
|
||||||
},
|
},
|
||||||
"messages" : [ { type: Messages.schema } ]
|
"messages" : [ { type: Messages.schema } ]
|
||||||
});
|
});
|
||||||
@@ -139,8 +139,8 @@ module.exports = {
|
|||||||
.sort({ order: 1 })
|
.sort({ order: 1 })
|
||||||
.populate({
|
.populate({
|
||||||
path: 'messages',
|
path: 'messages',
|
||||||
select: 'order text image isUser',
|
select: 'text image isUser timestamp',
|
||||||
options: { sort: { order: 1 } }
|
options: { sort: { timestamp: 1 } }
|
||||||
})
|
})
|
||||||
.exec((err, result) => {
|
.exec((err, result) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -163,7 +163,15 @@ module.exports = {
|
|||||||
|
|
||||||
allMessages: (e, profileId) => {
|
allMessages: (e, profileId) => {
|
||||||
const promise = new Promise((resolve, reject) => {
|
const promise = new Promise((resolve, reject) => {
|
||||||
ProfileModel.findById(profileId, (err, result) => {
|
ProfileModel
|
||||||
|
.find({ _id: profileId })
|
||||||
|
.select('messages')
|
||||||
|
.populate({
|
||||||
|
path: 'messages',
|
||||||
|
select: 'text image isUser timestamp',
|
||||||
|
options: { sort: { timestamp: 1 } }
|
||||||
|
})
|
||||||
|
.exec((err, result) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user