View chapter
This commit is contained in:
@@ -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')
|
router.route('/:id/chapters/add')
|
||||||
.get(function(request, response, next) {
|
.get(function(request, response, next) {
|
||||||
db.Entry.findByPk(request.params.id, {
|
db.Entry.findByPk(request.params.id, {
|
||||||
@@ -146,7 +127,7 @@ module.exports = function (options) {
|
|||||||
}).then(entry => {
|
}).then(entry => {
|
||||||
const isString = typeof request.body.text === "string" || request.body.text instanceof String
|
const isString = typeof request.body.text === "string" || request.body.text instanceof String
|
||||||
if (entry && isString) {
|
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({
|
db.Chapter.create({
|
||||||
name: chunks[0].trim(),
|
name: chunks[0].trim(),
|
||||||
entryId: entry.id,
|
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;
|
return router;
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user