comments
This commit is contained in:
27
server/routers/todo/model/todo/comment.js
Normal file
27
server/routers/todo/model/todo/comment.js
Normal file
@@ -0,0 +1,27 @@
|
||||
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)
|
||||
@@ -1,24 +1,37 @@
|
||||
const { Schema, model } = require('mongoose')
|
||||
const { Schema, model } = require("mongoose");
|
||||
|
||||
const { TODO_ITEM_MODEL_NAME, TODO_AUTH_USER_MODEL_NAME } = require('../../const')
|
||||
const {
|
||||
TODO_ITEM_MODEL_NAME,
|
||||
TODO_AUTH_USER_MODEL_NAME,
|
||||
TODO_AUTH_COMMENTS_MODEL_NAME,
|
||||
} = require("../../const");
|
||||
|
||||
const schema = new Schema({
|
||||
title: String,
|
||||
done: { type: Boolean, default: false },
|
||||
closed: Date,
|
||||
created: {
|
||||
type: Date, default: () => new Date().toISOString(),
|
||||
},
|
||||
createdBy: { type: Schema.Types.ObjectId, ref: TODO_AUTH_USER_MODEL_NAME },
|
||||
})
|
||||
title: String,
|
||||
done: { type: Boolean, default: false },
|
||||
closed: Date,
|
||||
created: {
|
||||
type: Date,
|
||||
default: () => new Date().toISOString(),
|
||||
},
|
||||
comments: [
|
||||
{ type: Schema.Types.ObjectId, ref: TODO_AUTH_COMMENTS_MODEL_NAME },
|
||||
],
|
||||
createdBy: { type: Schema.Types.ObjectId, ref: TODO_AUTH_USER_MODEL_NAME },
|
||||
});
|
||||
|
||||
schema.set('toJSON', {
|
||||
virtuals: true,
|
||||
versionKey: false,
|
||||
})
|
||||
schema.set("toJSON", {
|
||||
virtuals: true,
|
||||
versionKey: false,
|
||||
});
|
||||
|
||||
schema.virtual('id').get(function () {
|
||||
return this._id.toHexString()
|
||||
})
|
||||
schema.virtual("id").get(function () {
|
||||
return this._id.toHexString();
|
||||
});
|
||||
|
||||
exports.ItemModel = model(TODO_ITEM_MODEL_NAME, schema)
|
||||
schema.method('addComment', async function (commentId) {
|
||||
this.comments.push(commentId)
|
||||
await this.save()
|
||||
})
|
||||
|
||||
exports.ItemModel = model(TODO_ITEM_MODEL_NAME, schema);
|
||||
|
||||
Reference in New Issue
Block a user