Files
mantra.press/server/router/translate/index.js

77 lines
2.7 KiB
JavaScript

const express = require('express')
module.exports = function (options) {
const db = options.db;
var router = express.Router();
router.route('/:id')
.get(function(request, response, next) {
db.TranslationEntry.findByPk(request.params.id, {
include: [
{
association: db.TranslationEntry.Entry,
required: true,
include: [
{
association: db.Entry.Chapters,
required: true,
limit: 1,
// TODO: Order by chapter index
}
]
}
]
}).then(translationEntry => {
if (translationEntry) {
response.redirect(`/translate/${translationEntry.id}/chapter/${translationEntry.entry.chapters[0].id}`)
} else {
next()
}
})
})
router.route('/:id/chapter/:chapterId')
.get(function(request, response, next) {
db.Chapter.findByPk(request.params.chapterId, {
include: [
{
association: db.Chapter.Chunks,
include: [
{
association: db.Chunk.Translation
}
]
},
{
association: db.Chapter.Entry,
required: true,
include: [
{
association: db.Entry.TranslationEntries,
required: true,
where: {
id: request.params.id
}
},
{
association: db.Entry.Dialect
}
]
}
]
}).then(chapter => {
if (chapter) {
response.display("translate-chapter", {
user: request.user,
pageTitle: `Translate Chapter ${chapter.name}`,
chapter: chapter
})
} else {
next()
}
}).catch(error => {
next(error)
})
})
return router;
};