View chapter

This commit is contained in:
2021-12-19 21:25:47 +02:00
parent 722c6a9bc5
commit 46ca5a9a6d

View File

@@ -88,25 +88,6 @@ module.exports = function (options) {
})
})
router.route('/:id/chapters/:chapterId')
.get(function(request, response, next) {
db.Chapter.findByPk(request.params.chapterId, {
include: [
{
association: db.Chapter.Chunks
}
]
}).then(chapter => {
response.display("chapter", {
user: request.user,
pageTitle: "Chapter - Mantra",
chapter: chapter
})
}).catch(error => {
next(error)
})
})
router.route('/:id/chapters/add')
.get(function(request, response, next) {
db.Entry.findByPk(request.params.id, {
@@ -146,7 +127,7 @@ module.exports = function (options) {
}).then(entry => {
const isString = typeof request.body.text === "string" || request.body.text instanceof String
if (entry && isString) {
const chunks = new String(request.body.text.trim()).split(/\r?\n\r?\n/)
const chunks = request.body.text.trim().split(/\r?\n\r?\n/)
db.Chapter.create({
name: chunks[0].trim(),
entryId: entry.id,
@@ -178,5 +159,30 @@ module.exports = function (options) {
})
})
router.route('/:id/chapters/:chapterId')
.get(function(request, response, next) {
db.Chapter.findByPk(request.params.chapterId, {
include: [
{
association: db.Chapter.Chunks
},
{
association: db.Chapter.Entry
}
]
}).then(chapter => {
if (chapter) {
response.display("chapter", {
user: request.user,
pageTitle: "Chapter - Mantra",
chapter: chapter
})
} else {
next()
}
}).catch(error => {
next(error)
})
})
return router;
};