28 lines
794 B
JavaScript
28 lines
794 B
JavaScript
const { Schema, model } = require('mongoose')
|
|
|
|
const { TODO_AUTH_COMMENTS_MODEL_NAME, TODO_AUTH_USER_MODEL_NAME } = require('../../const')
|
|
|
|
const schema = new Schema({
|
|
text: String,
|
|
created: {
|
|
type: Date, default: () => new Date().toISOString(),
|
|
},
|
|
answerTo: { type: Schema.Types.ObjectId, ref: TODO_AUTH_COMMENTS_MODEL_NAME },
|
|
createdBy: { type: Schema.Types.ObjectId, ref: TODO_AUTH_USER_MODEL_NAME },
|
|
author: { type: Schema.Types.ObjectId, ref: TODO_AUTH_USER_MODEL_NAME },
|
|
})
|
|
|
|
schema.set('toJSON', {
|
|
virtuals: true,
|
|
versionKey: false,
|
|
transform: function (doc, ret) {
|
|
delete ret._id
|
|
}
|
|
})
|
|
|
|
schema.virtual('id').get(function () {
|
|
return this._id.toHexString()
|
|
})
|
|
|
|
exports.CommentModel = model(TODO_AUTH_COMMENTS_MODEL_NAME, schema)
|