mode todo in todo folder
This commit is contained in:
23
server/routers/todo/model/todo/item.js
Normal file
23
server/routers/todo/model/todo/item.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const { Schema, model } = require('mongoose')
|
||||
|
||||
const { TODO_ITEM_MODEL_NAME } = require('../../const')
|
||||
|
||||
const schema = new Schema({
|
||||
title: String,
|
||||
done: { type: Boolean, default: false },
|
||||
closed: Date,
|
||||
created: {
|
||||
type: Date, default: () => new Date().toISOString(),
|
||||
},
|
||||
})
|
||||
|
||||
schema.set('toJSON', {
|
||||
virtuals: true,
|
||||
versionKey: false,
|
||||
})
|
||||
|
||||
schema.virtual('id').get(function () {
|
||||
return this._id.toHexString()
|
||||
})
|
||||
|
||||
exports.ItemModel = model(TODO_ITEM_MODEL_NAME, schema)
|
||||
27
server/routers/todo/model/todo/list.js
Normal file
27
server/routers/todo/model/todo/list.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const { Schema, model } = require('mongoose')
|
||||
|
||||
const { TODO_LIST_MODEL_NAME, TODO_ITEM_MODEL_NAME } = require('../../const')
|
||||
|
||||
const schema = new Schema({
|
||||
title: String,
|
||||
created: {
|
||||
type: Date, default: () => new Date().toISOString(),
|
||||
},
|
||||
items: [{ type: Schema.Types.ObjectId, ref: TODO_ITEM_MODEL_NAME }],
|
||||
})
|
||||
|
||||
schema.set('toJSON', {
|
||||
virtuals: true,
|
||||
versionKey: false,
|
||||
})
|
||||
|
||||
schema.virtual('id').get(function () {
|
||||
return this._id.toHexString()
|
||||
})
|
||||
|
||||
schema.method('addItem', async function (itemObjectId) {
|
||||
this.items.push(itemObjectId)
|
||||
await this.save()
|
||||
})
|
||||
|
||||
exports.ListModel = model(TODO_LIST_MODEL_NAME, schema)
|
||||
Reference in New Issue
Block a user