// comment.js // Copyright (C) 2021 Digital Telepresence, LLC // License: Apache-2.0 'use strict'; const path = require('path'); const mongoose = require('mongoose'); const Schema = mongoose.Schema; const { CommentStats, CommentStatsDefaults } = require(path.join(__dirname, 'lib', 'resource-stats.js')); const CommentSchema = new Schema({ created: { type: Date, default: Date.now, required: true, index: 1 }, resourceType: { type: String, enum: ['Post', 'Page', 'Newsletter'], required: true }, resource: { type: Schema.ObjectId, required: true, index: 1, refPath: 'resourceType' }, replyTo: { type: Schema.ObjectId, index: 1, ref: 'Comment' }, author: { type: Schema.ObjectId, required: true, index: 1, ref: 'User' }, content: { type: String, required: true, maxlength: 3000 }, stats: { type: CommentStats, default: CommentStatsDefaults, required: true }, }); module.exports = mongoose.model('Comment', CommentSchema);