mirror of
https://github.com/usatiuk/ustk-todolist.git
synced 2025-10-28 23:57:49 +01:00
use list id for routing
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
const mongoose = require('mongoose');
|
||||
const slugify = require('slugify');
|
||||
|
||||
const { Schema } = mongoose;
|
||||
|
||||
@@ -8,25 +7,9 @@ const TodoListSchema = Schema({
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
slug: {
|
||||
type: String,
|
||||
required: true,
|
||||
lowercase: true,
|
||||
},
|
||||
todos: [{ type: Schema.Types.ObjectId, ref: 'Todo' }],
|
||||
});
|
||||
|
||||
TodoListSchema.pre('validate', function (next) {
|
||||
if (!this.slug) {
|
||||
this.slugify();
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
TodoListSchema.methods.slugify = function () {
|
||||
this.slug = slugify(this.name);
|
||||
};
|
||||
|
||||
TodoListSchema.pre('remove', async function () {
|
||||
this.todos.forEach(async (todo) => {
|
||||
await todo.remove();
|
||||
@@ -38,7 +21,6 @@ TodoListSchema.methods.toJson = function () {
|
||||
return {
|
||||
id: this._id.toString(),
|
||||
name: this.name,
|
||||
slug: this.slug,
|
||||
todos,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user