mirror of
https://github.com/usatiuk/ustk-todolist.git
synced 2025-10-28 15:47:48 +01:00
18 lines
458 B
JavaScript
18 lines
458 B
JavaScript
const mongoose = require('mongoose');
|
|
const asyncHelper = require('../asyncHelper');
|
|
|
|
const TodoList = mongoose.model('TodoList');
|
|
|
|
const { NotFoundError } = require('../errors');
|
|
|
|
// listId middleware
|
|
module.exports = asyncHelper(async (req, res, next) => {
|
|
const { slug } = req.params;
|
|
const list = await TodoList.findOne({ slug }).exec();
|
|
if (!list) {
|
|
throw new NotFoundError('cant find list');
|
|
}
|
|
res.locals.listId = list._id;
|
|
next();
|
|
});
|