mirror of
https://github.com/wassname/talk.git
synced 2026-07-10 07:33:13 +08:00
42 lines
807 B
JavaScript
42 lines
807 B
JavaScript
const mongoose = require('../mongoose');
|
|
const uuid = require('uuid');
|
|
const Schema = mongoose.Schema;
|
|
|
|
const CommentSchema = new Schema({
|
|
id: {
|
|
type: String,
|
|
default: uuid.v4,
|
|
unique: true
|
|
},
|
|
body: {
|
|
type: String,
|
|
required: [true, 'The body is required.'],
|
|
minlength: 10
|
|
},
|
|
asset_id: String,
|
|
author_id: String,
|
|
status: {
|
|
type: String,
|
|
enum: ['accepted', 'rejected', ''],
|
|
default: ''
|
|
},
|
|
parent_id: String
|
|
},{
|
|
timestamps: {
|
|
createdAt: 'created_at',
|
|
updatedAt: 'updated_at'
|
|
}
|
|
});
|
|
|
|
/**
|
|
* Finds a comment by the id.
|
|
* @param {String} id identifier of the comment (uuid)
|
|
*/
|
|
CommentSchema.statics.findById = function(id) {
|
|
return Comment.findOne({id});
|
|
};
|
|
|
|
const Comment = mongoose.model('Comment', CommentSchema);
|
|
|
|
module.exports = Comment;
|