Main functionality for translation entries
This commit is contained in:
15
server/router/api/index.js
Normal file
15
server/router/api/index.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const express = require('express')
|
||||
|
||||
module.exports = function (options) {
|
||||
const db = options.db;
|
||||
var router = express.Router();
|
||||
|
||||
router.route('/dialects')
|
||||
.get(function(request, response, next) {
|
||||
db.Dialect.findAll({
|
||||
}).then(dialects => {
|
||||
response.json(dialects)
|
||||
})
|
||||
})
|
||||
return router;
|
||||
};
|
||||
@@ -21,11 +21,14 @@ module.exports = function (options) {
|
||||
var libraryRouter = require('./library')(options);
|
||||
var pledgesRouter = require('./pledges/')(options);
|
||||
var campaignsRouter = require('./campaigns/')(options);
|
||||
var apiRouter = require('./api/')(options);
|
||||
|
||||
|
||||
router.use('/library', libraryRouter);
|
||||
router.use('/pledges', pledgesRouter);
|
||||
router.use('/campaigns', campaignsRouter);
|
||||
router.use('/account', accountRouter);
|
||||
router.use('/api', apiRouter);
|
||||
|
||||
return router;
|
||||
};
|
||||
@@ -184,5 +184,106 @@ module.exports = function (options) {
|
||||
next(error)
|
||||
})
|
||||
})
|
||||
|
||||
router.route('/:id/translations/:translationEntryid')
|
||||
.get(function(request, response, next) {
|
||||
db.TranslationEntry.findByPk(request.params.translationEntryid, {
|
||||
include: [
|
||||
{
|
||||
association: db.TranslationEntry.Entry
|
||||
}
|
||||
]
|
||||
}).then(translationEntry => {
|
||||
if (translationEntry) {
|
||||
response.display("translation-entry", {
|
||||
user: request.user,
|
||||
pageTitle: "Translation Entry - Mantra",
|
||||
translationEntry: translationEntry,
|
||||
})
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
}).catch(error => {
|
||||
next(error)
|
||||
})
|
||||
})
|
||||
|
||||
router.route('/:id/translations/add')
|
||||
.get(function(request, response, next) {
|
||||
db.Entry.findByPk(request.params.id, {
|
||||
include: [
|
||||
{
|
||||
association: db.Entry.EntryApproval
|
||||
},
|
||||
{
|
||||
association: db.Entry.TranslationEntries
|
||||
}
|
||||
]
|
||||
}).then(entry => {
|
||||
if (entry) {
|
||||
response.display("translation-form", {
|
||||
user: request.user,
|
||||
pageTitle: "Library - Mantra",
|
||||
entry: entry
|
||||
})
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
|
||||
}).catch(error => {
|
||||
next(error)
|
||||
})
|
||||
})
|
||||
.post(function(request, response, next) {
|
||||
db.Entry.findByPk(request.params.id, {
|
||||
include: [
|
||||
{
|
||||
association: db.Entry.EntryApproval
|
||||
},
|
||||
{
|
||||
association: db.Entry.TranslationEntries
|
||||
},
|
||||
{
|
||||
association: db.Entry.Chapters,
|
||||
include: [
|
||||
{
|
||||
association: db.Chapter.Chunks
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}).then(async (entry) => {
|
||||
if (entry) {
|
||||
const dialectTokens = request.body.dialect?.split(":")
|
||||
if (dialectTokens?.length == 2) {
|
||||
const countryId = dialectTokens[0].split("-")[0]
|
||||
const languageId = dialectTokens[0].split("-")[1]
|
||||
|
||||
const dialect = await db.Dialect.findOne({
|
||||
where: {
|
||||
countryId: countryId,
|
||||
languageId: languageId
|
||||
}
|
||||
})
|
||||
|
||||
if (dialect) {
|
||||
const translationEntry = await db.TranslationEntry.create({
|
||||
name: dialect.name,
|
||||
entryId: entry.id,
|
||||
dialectId: dialect.id
|
||||
})
|
||||
|
||||
if (translationEntry) {
|
||||
return response.redirect(`/library/${entry.id}/translations/${translationEntry.id}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
next()
|
||||
}).catch(error => {
|
||||
next(error)
|
||||
})
|
||||
})
|
||||
|
||||
return router;
|
||||
};
|
||||
Reference in New Issue
Block a user