Handle forks with care
This commit is contained in:
@@ -7,9 +7,32 @@ module.exports = function (options) {
|
|||||||
router.route('/t/:id')
|
router.route('/t/:id')
|
||||||
.post(function(request, response, next) {
|
.post(function(request, response, next) {
|
||||||
db.TranslationArtifactVersion.findByPk(request.params.id, {
|
db.TranslationArtifactVersion.findByPk(request.params.id, {
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.TranslationArtifactVersion.Forks,
|
||||||
|
required: false,
|
||||||
|
where: {
|
||||||
|
// TODO: use entityId as query...
|
||||||
|
creatorId: request.user.id
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
association: db.TranslationArtifactVersion.TranslationChapters,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.TranslationChapter.TranslationChunks,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.TranslationChunk.Translation
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
}).then(async (translationArtifactVersion) => {
|
}).then(async (translationArtifactVersion) => {
|
||||||
if (translationArtifactVersion) {
|
if (translationArtifactVersion) {
|
||||||
// fork...
|
// fork check if forkable...
|
||||||
const forkedTranslationArtifactVersion = await db.TranslationArtifactVersion.create({
|
const forkedTranslationArtifactVersion = await db.TranslationArtifactVersion.create({
|
||||||
creatorId: request.user.id,
|
creatorId: request.user.id,
|
||||||
name: translationArtifactVersion.name,
|
name: translationArtifactVersion.name,
|
||||||
@@ -17,7 +40,41 @@ module.exports = function (options) {
|
|||||||
userId: request.user.id,
|
userId: request.user.id,
|
||||||
dialectId: translationArtifactVersion.dialectId,
|
dialectId: translationArtifactVersion.dialectId,
|
||||||
forkedFromId: translationArtifactVersion.id,
|
forkedFromId: translationArtifactVersion.id,
|
||||||
entityId: request.user.individualEntityUser.entityUser.entityId
|
entityId: request.user.individualEntityUser.entityUser.entityId,
|
||||||
|
translationChapters: translationArtifactVersion.translationChapters.map(translationChapter => {
|
||||||
|
return {
|
||||||
|
creatorId: request.user.id,
|
||||||
|
chapterId: translationChapter.chapterId,
|
||||||
|
translationChunks: translationChapter.translationChunks.map(translationChunk => {
|
||||||
|
const tc = {
|
||||||
|
creatorId: request.user.id,
|
||||||
|
chunkId: translationChunk.chunkId,
|
||||||
|
text: translationChunk.text,
|
||||||
|
index: translationChunk.index,
|
||||||
|
}
|
||||||
|
// if (translationChunk.translation) {
|
||||||
|
// tc.translation = {
|
||||||
|
// creatorId: translationChunk.translation.creatorId,
|
||||||
|
// text: translationChunk.translation.text,
|
||||||
|
// // TODO: Might want to create translations separately...
|
||||||
|
// translationArtifactVersionId: translationChunk.translation.translationArtifactVersionId,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
return tc
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}, {
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.TranslationArtifactVersion.TranslationChapters,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.TranslationChapter.TranslationChunks,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
})
|
})
|
||||||
if (forkedTranslationArtifactVersion) {
|
if (forkedTranslationArtifactVersion) {
|
||||||
return response.redirect(`/v/${forkedTranslationArtifactVersion.artifactVersionId}/translations/${forkedTranslationArtifactVersion.id}`)
|
return response.redirect(`/v/${forkedTranslationArtifactVersion.artifactVersionId}/translations/${forkedTranslationArtifactVersion.id}`)
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ module.exports = function (options) {
|
|||||||
{
|
{
|
||||||
association: db.ArtifactVersion.TranslationArtifactVersions,
|
association: db.ArtifactVersion.TranslationArtifactVersions,
|
||||||
where: {
|
where: {
|
||||||
backTranslationFromId: null
|
backTranslationFromId: null,
|
||||||
|
forkedFromId: null
|
||||||
},
|
},
|
||||||
required: false
|
required: false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user