More edit changes

This commit is contained in:
Wyatt Johnson
2017-05-12 10:09:25 -06:00
parent f4dfb21e15
commit ed27209de9
10 changed files with 218 additions and 196 deletions
+11
View File
@@ -2,6 +2,8 @@ const mongoose = require('../services/mongoose');
const Schema = mongoose.Schema;
const uuid = require('uuid');
const EDIT_WINDOW_MS = 30 * 1000; // 30 seconds
const STATUSES = [
'ACCEPTED',
'REJECTED',
@@ -107,7 +109,16 @@ const CommentSchema = new Schema({
}
});
CommentSchema.virtual('edited').get(function() {
return this.body_history.length > 1;
});
CommentSchema.virtual('editableUntil').get(function() {
return new Date(Number(this.created_at) + EDIT_WINDOW_MS);
});
// Comment model.
const Comment = mongoose.model('Comment', CommentSchema);
module.exports = Comment;
module.exports.EDIT_WINDOW_MS = EDIT_WINDOW_MS;