mirror of
https://github.com/usatiuk/ustk-todolist.git
synced 2025-10-28 15:47:48 +01:00
use slugs for lists
This commit is contained in:
@@ -7,6 +7,10 @@ const todoListSchema = Schema({
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
slug: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
todos: [{ type: Schema.Types.ObjectId, ref: 'Todo' }],
|
||||
});
|
||||
|
||||
|
||||
5
package-lock.json
generated
5
package-lock.json
generated
@@ -9709,6 +9709,11 @@
|
||||
"resolved": "https://registry.npmjs.org/sliced/-/sliced-1.0.1.tgz",
|
||||
"integrity": "sha1-CzpmK10Ewxd7GSa+qCsD+Dei70E="
|
||||
},
|
||||
"slugify": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/slugify/-/slugify-1.3.0.tgz",
|
||||
"integrity": "sha512-vvz+9ANt7CtdTHwJpfrsHOnGkgxky+CUPnvtzDZBZYFo/H/CdZkd5lJL7z7RqtH/x9QW/ItYYfHlcGf38CBK1w=="
|
||||
},
|
||||
"snapdragon": {
|
||||
"version": "0.8.2",
|
||||
"resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz",
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
"method-override": "^2.3.10",
|
||||
"mongoose": "^5.1.1",
|
||||
"morgan": "^1.9.0",
|
||||
"npm": "^6.0.1"
|
||||
"npm": "^6.0.1",
|
||||
"slugify": "^1.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^4.19.1",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const express = require('express');
|
||||
const mongoose = require('mongoose');
|
||||
const slugify = require('slugify');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -26,16 +27,17 @@ router.post(
|
||||
asyncHelper(async (req, res) => {
|
||||
const { name } = req.body;
|
||||
const newList = new TodoList({ name });
|
||||
newList.slug = slugify(name);
|
||||
await newList.save();
|
||||
res.json({ success: true });
|
||||
}),
|
||||
);
|
||||
|
||||
router.delete(
|
||||
'/:id',
|
||||
'/:slug',
|
||||
asyncHelper(async (req, res) => {
|
||||
const { id } = req.params;
|
||||
const list = await TodoList.findById(id)
|
||||
const { slug } = req.params;
|
||||
const list = await TodoList.findOne({ slug })
|
||||
.populate('todos')
|
||||
.exec();
|
||||
if (!list) {
|
||||
|
||||
Reference in New Issue
Block a user