Assign and view translator
This commit is contained in:
@@ -1164,6 +1164,21 @@ module.exports = function (options) {
|
||||
},
|
||||
{
|
||||
association: db.TranslationChapter.TranslationChapterTranslators,
|
||||
include: [
|
||||
{
|
||||
association: db.TranslationChapterTranslator.Translator,
|
||||
include: [
|
||||
{
|
||||
association: db.Entity.EntityEmail,
|
||||
include: [
|
||||
{
|
||||
association: db.EntityEmail.Email
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
association: db.TranslationChapter.TranslationChapterProofReaders,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const express = require('express')
|
||||
const { Op } = require("sequelize")
|
||||
const idGenerator = require('mantra-db-models/src/lib/id-generator')
|
||||
|
||||
module.exports = function (options) {
|
||||
const db = options.db;
|
||||
@@ -111,6 +112,21 @@ module.exports = function (options) {
|
||||
},
|
||||
{
|
||||
association: db.TranslationChapter.TranslationChapterTranslators,
|
||||
include: [
|
||||
{
|
||||
association: db.TranslationChapterTranslator.Translator,
|
||||
include: [
|
||||
{
|
||||
association: db.Entity.EntityEmail,
|
||||
include: [
|
||||
{
|
||||
association: db.EntityEmail.Email
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
association: db.TranslationChapter.TranslationChapterProofReaders,
|
||||
@@ -849,5 +865,208 @@ module.exports = function (options) {
|
||||
next(error)
|
||||
})
|
||||
})
|
||||
|
||||
router.route('/:id/chapter/:chapterId/translator')
|
||||
.get(function(request, response, next) {
|
||||
db.TranslationChapter.findByPk(request.params.chapterId, {
|
||||
include: [
|
||||
{
|
||||
association: db.TranslationChapter.Chapter,
|
||||
},
|
||||
{
|
||||
association: db.TranslationChapter.TranslationChapterTranslators,
|
||||
},
|
||||
{
|
||||
association: db.TranslationChapter.TranslationChapterProofReaders,
|
||||
},
|
||||
{
|
||||
association: db.TranslationChapter.TranslationChunks,
|
||||
include: [
|
||||
{
|
||||
association: db.TranslationChunk.Translation
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
association: db.TranslationChapter.TranslationArtifactVersion,
|
||||
include: [
|
||||
{
|
||||
association: db.TranslationArtifactVersion.ArtifactVersion,
|
||||
include: [
|
||||
{
|
||||
association: db.ArtifactVersion.Artifact,
|
||||
include: [
|
||||
{
|
||||
association: db.Artifact.Dialect
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
association: db.TranslationArtifactVersion.Dialect
|
||||
},
|
||||
{
|
||||
association: db.TranslationArtifactVersion.BackTranslationFrom
|
||||
},
|
||||
{
|
||||
association: db.TranslationArtifactVersion.TranslationArtifactVersionEditor,
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}).then(translationChapter => {
|
||||
if (translationChapter) {
|
||||
response.display("translate-chapter-translator-form", {
|
||||
user: request.user,
|
||||
pageTitle: `Translate Chapter ${translationChapter.name}`,
|
||||
translationChapter: translationChapter
|
||||
})
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
}).catch(error => {
|
||||
next(error)
|
||||
})
|
||||
})
|
||||
.post(function(request, response, next) {
|
||||
db.TranslationChapter.findByPk(request.params.chapterId, {
|
||||
include: [
|
||||
{
|
||||
association: db.TranslationChapter.Chapter,
|
||||
},
|
||||
{
|
||||
association: db.TranslationChapter.TranslationChapterTranslators,
|
||||
},
|
||||
{
|
||||
association: db.TranslationChapter.TranslationChapterProofReaders,
|
||||
},
|
||||
{
|
||||
association: db.TranslationChapter.TranslationChunks,
|
||||
include: [
|
||||
{
|
||||
association: db.TranslationChunk.Translation
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
association: db.TranslationChapter.TranslationArtifactVersion,
|
||||
include: [
|
||||
{
|
||||
association: db.TranslationArtifactVersion.ArtifactVersion,
|
||||
include: [
|
||||
{
|
||||
association: db.ArtifactVersion.Artifact,
|
||||
include: [
|
||||
{
|
||||
association: db.Artifact.Dialect
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
association: db.TranslationArtifactVersion.Dialect
|
||||
},
|
||||
{
|
||||
association: db.TranslationArtifactVersion.BackTranslationFrom
|
||||
},
|
||||
{
|
||||
association: db.TranslationArtifactVersion.TranslationArtifactVersionEditor,
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}).then(async (translationChapter) => {
|
||||
if (translationChapter) {
|
||||
// TODO: Check if translationChapter has a TranslationChapterTranslator with this email...
|
||||
// TODO: FindOrCreate Email
|
||||
const [email, created] = await db.Email.findOrCreate({
|
||||
where: {
|
||||
address: request.body.translator
|
||||
},
|
||||
include: [
|
||||
{
|
||||
association: db.Email.EntityEmails,
|
||||
required: false,
|
||||
where: {
|
||||
creatorId: request.user.id
|
||||
}
|
||||
},
|
||||
{
|
||||
association: db.Email.UserEmail,
|
||||
include: [
|
||||
{
|
||||
association: db.UserEmail.User,
|
||||
include: [
|
||||
{
|
||||
association: db.User.IndividualEntityUser,
|
||||
include: [
|
||||
{
|
||||
association: db.IndividualEntityUser.EntityUser
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
defaults: {
|
||||
address: request.body.translator
|
||||
}
|
||||
})
|
||||
console.log("Email: ", email.toJSON())
|
||||
if (email.userEmail) {
|
||||
// if email has user associated with it tie that users individual entity to a new TranslationChapterTranslator object
|
||||
await db.TranslationChapterTranslator.create({
|
||||
translationChapterId: translationChapter.id,
|
||||
creatorId: request.user.id,
|
||||
translatorId: email.userEmail.user.individualEntityUser.entityUser.entityId
|
||||
})
|
||||
} else if (email.entityEmails?.length > 0) {
|
||||
// TODO: If email has an EntityEmail (which has this user as a creator) tie that entityEmail to a new TranslationChapterTranslator
|
||||
await db.TranslationChapterTranslator.create({
|
||||
translationChapterId: translationChapter.id,
|
||||
creatorId: request.user.id,
|
||||
translatorId: email.entityEmails[0].entityId
|
||||
})
|
||||
} else {
|
||||
// if email doesn't have a user/entityEmail associated with it (newly created) create an EntityEmail and tie it to a new TranslationChapterTranslator object
|
||||
await db.TranslationChapterTranslator.create({
|
||||
translationChapterId: translationChapter.id,
|
||||
creatorId: request.user.id,
|
||||
translator: {
|
||||
name: idGenerator.generateRandomAlphanumeric(),
|
||||
type: "individual",
|
||||
entityEmail: {
|
||||
creatorId: request.user.id,
|
||||
emailAddress: email.address,
|
||||
type: 'translator'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
include: [
|
||||
{
|
||||
association: db.TranslationChapterTranslator.Translator,
|
||||
include: [
|
||||
{
|
||||
association: db.Entity.EntityEmail
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
response.redirect(`/translate/${translationChapter.translationArtifactVersion.id}/chapter/${translationChapter.id}`)
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
}).catch(error => {
|
||||
next(error)
|
||||
})
|
||||
})
|
||||
|
||||
return router;
|
||||
};
|
||||
Reference in New Issue
Block a user