no message
This commit is contained in:
@@ -1,14 +1,7 @@
|
||||
const fs = require('fs');
|
||||
const Images = require('../modules/images');
|
||||
const Messages = require('../models/message');
|
||||
const Mongoose = require('mongoose');
|
||||
const ShortId = require('shortid');
|
||||
|
||||
const ATTACHMENT_STORE = '../images';
|
||||
const ATTACHMENT_STORE_PROFILE = '/profile';
|
||||
const ATTACHMENT_STORE_MESSAGE = '/message';
|
||||
const ATTACHMENT_SUFFIX_DETAIL = '_detail';
|
||||
const ATTACHMENT_SUFFIX_THUMBNAIL = '_thumbnail';
|
||||
|
||||
const ProfileSchema = new Mongoose.Schema({
|
||||
"order" : { type: Number, default: 0 },
|
||||
"details": {
|
||||
@@ -34,6 +27,88 @@ const ProfileSchema = new Mongoose.Schema({
|
||||
"messages" : [ { type: Messages.schema } ]
|
||||
});
|
||||
|
||||
ProfileSchema.pre('findOneAndUpdate', function (next) {
|
||||
var cnt = 0;
|
||||
|
||||
if (this.details && this.details.pic) {
|
||||
var pic = this.details.pic
|
||||
cnt = cnt + (typeof pic.detail === 'object' ? 1 : 0) + (typeof pic.thumb === 'object' ? 1 : 0);
|
||||
}
|
||||
|
||||
if (cnt > 0) {
|
||||
if (typeof pic.detail === 'object') {
|
||||
Images.saveProfileDetailImage(pic.detail, (err, filename) => {
|
||||
if (err) {
|
||||
Logger.error('[MessageSchema.pre(save)] There was an error processing the message image. [' + err + ']', { error: err });
|
||||
}
|
||||
|
||||
if (filename) {
|
||||
pic.detail = filename;
|
||||
cnt -= 1;
|
||||
if (cnt === 0) next();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof pic.thumb === 'object') {
|
||||
Images.saveProfileThumbnailImage(pic.thumb, (err, filename) => {
|
||||
if (err) {
|
||||
Logger.error('[MessageSchema.pre(save)] There was an error processing the message image. [' + err + ']', { error: err });
|
||||
}
|
||||
|
||||
if (filename) {
|
||||
pic.thumb = filename;
|
||||
cnt -= 1;
|
||||
if (cnt === 0) next();
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
|
||||
ProfileSchema.pre('save', function (next) {
|
||||
var cnt = 0;
|
||||
|
||||
if (this.details && this.details.pic) {
|
||||
var pic = this.details.pic
|
||||
cnt = cnt + (typeof pic.detail === 'object' ? 1 : 0) + (typeof pic.thumb === 'object' ? 1 : 0);
|
||||
}
|
||||
|
||||
if (cnt > 0) {
|
||||
if (typeof pic.detail === 'object') {
|
||||
Images.saveProfileDetailImage(pic.detail, (err, filename) => {
|
||||
if (err) {
|
||||
Logger.error('[MessageSchema.pre(save)] There was an error processing the message image. [' + err + ']', { error: err });
|
||||
}
|
||||
|
||||
if (filename) {
|
||||
pic.detail = filename;
|
||||
cnt -= 1;
|
||||
if (cnt === 0) next();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof pic.thumb === 'object') {
|
||||
Images.saveProfileThumbnailImage(pic.thumb, (err, filename) => {
|
||||
if (err) {
|
||||
Logger.error('[MessageSchema.pre(save)] There was an error processing the message image. [' + err + ']', { error: err });
|
||||
}
|
||||
|
||||
if (filename) {
|
||||
pic.thumb = filename;
|
||||
cnt -= 1;
|
||||
if (cnt === 0) next();
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
|
||||
const ProfileModel = Mongoose.model('profiles', ProfileSchema);
|
||||
|
||||
module.exports = {
|
||||
|
||||
Reference in New Issue
Block a user