Handle owner with null userId
This commit is contained in:
@@ -6,111 +6,114 @@ 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, {
|
if (request.user) {
|
||||||
include: [
|
db.TranslationArtifactVersion.findByPk(request.params.id, {
|
||||||
{
|
include: [
|
||||||
association: db.TranslationArtifactVersion.Forks,
|
{
|
||||||
required: false,
|
association: db.TranslationArtifactVersion.Forks,
|
||||||
where: {
|
required: false,
|
||||||
// TODO: use entityId as query...
|
where: {
|
||||||
creatorId: request.user.id
|
// TODO: use entityId as query...
|
||||||
}
|
creatorId: request.user.id
|
||||||
},
|
|
||||||
{
|
|
||||||
association: db.TranslationArtifactVersion.TranslationChapters,
|
|
||||||
include: [
|
|
||||||
{
|
|
||||||
association: db.TranslationChapter.TranslationChunks,
|
|
||||||
include: [
|
|
||||||
{
|
|
||||||
association: db.TranslationChunk.Translation
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
},
|
||||||
}
|
{
|
||||||
]
|
association: db.TranslationArtifactVersion.TranslationChapters,
|
||||||
}).then(async (translationArtifactVersion) => {
|
include: [
|
||||||
if (translationArtifactVersion) {
|
|
||||||
const existingTranslation = {}
|
|
||||||
// fork check if forkable...
|
|
||||||
const forkedTranslationArtifactVersion = await db.TranslationArtifactVersion.create({
|
|
||||||
creatorId: request.user.id,
|
|
||||||
name: translationArtifactVersion.name,
|
|
||||||
artifactVersionId: translationArtifactVersion.artifactVersionId,
|
|
||||||
userId: request.user.id,
|
|
||||||
dialectId: translationArtifactVersion.dialectId,
|
|
||||||
forkedFromId: translationArtifactVersion.id,
|
|
||||||
owner: {
|
|
||||||
ownerEntities: [
|
|
||||||
{
|
{
|
||||||
entityId: request.user.individualEntityUser.entityUser.entityId,
|
association: db.TranslationChapter.TranslationChunks,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.TranslationChunk.Translation
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
translationChapters: translationArtifactVersion.translationChapters.map(translationChapter => {
|
]
|
||||||
return {
|
}).then(async (translationArtifactVersion) => {
|
||||||
creatorId: request.user.id,
|
if (translationArtifactVersion) {
|
||||||
chapterId: translationChapter.chapterId,
|
const existingTranslation = {}
|
||||||
translationChunks: translationChapter.translationChunks.map(translationChunk => {
|
// fork check if forkable...
|
||||||
if (translationChunk.translation) {
|
const forkedTranslationArtifactVersion = await db.TranslationArtifactVersion.create({
|
||||||
existingTranslation[translationChunk.chunkId] = {
|
creatorId: request.user.id,
|
||||||
creatorId: translationChunk.translation.creatorId,
|
name: translationArtifactVersion.name,
|
||||||
text: translationChunk.translation.text,
|
artifactVersionId: translationArtifactVersion.artifactVersionId,
|
||||||
}
|
userId: request.user.id,
|
||||||
}
|
dialectId: translationArtifactVersion.dialectId,
|
||||||
return {
|
forkedFromId: translationArtifactVersion.id,
|
||||||
creatorId: request.user.id,
|
owner: {
|
||||||
chunkId: translationChunk.chunkId,
|
ownerEntities: [
|
||||||
text: translationChunk.text,
|
|
||||||
index: translationChunk.index,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}, {
|
|
||||||
include: [
|
|
||||||
{
|
|
||||||
association: db.TranslationArtifactVersion.TranslationChapters,
|
|
||||||
include: [
|
|
||||||
{
|
{
|
||||||
association: db.TranslationChapter.TranslationChunks,
|
entityId: request.user.individualEntityUser.entityUser.entityId,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
translationChapters: translationArtifactVersion.translationChapters.map(translationChapter => {
|
||||||
association: db.TranslationArtifactVersion.Owner,
|
return {
|
||||||
include: [
|
creatorId: request.user.id,
|
||||||
{
|
chapterId: translationChapter.chapterId,
|
||||||
association: db.Owner.OwnerEntities
|
translationChunks: translationChapter.translationChunks.map(translationChunk => {
|
||||||
}
|
if (translationChunk.translation) {
|
||||||
]
|
existingTranslation[translationChunk.chunkId] = {
|
||||||
}
|
creatorId: translationChunk.translation.creatorId,
|
||||||
]
|
text: translationChunk.translation.text,
|
||||||
})
|
}
|
||||||
if (forkedTranslationArtifactVersion) {
|
}
|
||||||
const t = []
|
return {
|
||||||
forkedTranslationArtifactVersion.translationChapters.forEach(translationChapter => {
|
creatorId: request.user.id,
|
||||||
translationChapter.translationChunks.forEach(translationChunk => {
|
chunkId: translationChunk.chunkId,
|
||||||
if (existingTranslation[translationChunk.chunkId]) {
|
text: translationChunk.text,
|
||||||
t.push({
|
index: translationChunk.index,
|
||||||
translationChunkId: translationChunk.id,
|
}
|
||||||
creatorId: existingTranslation[translationChunk.chunkId].creatorId,
|
|
||||||
text: existingTranslation[translationChunk.chunkId].text,
|
|
||||||
translationArtifactVersionId: forkedTranslationArtifactVersion.id
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
}, {
|
||||||
await db.Translation.bulkCreate(t)
|
include: [
|
||||||
return response.redirect(`/translate/${forkedTranslationArtifactVersion.id}`)
|
{
|
||||||
|
association: db.TranslationArtifactVersion.TranslationChapters,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.TranslationChapter.TranslationChunks,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
association: db.TranslationArtifactVersion.Owner,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.Owner.OwnerEntities
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
if (forkedTranslationArtifactVersion) {
|
||||||
|
const t = []
|
||||||
|
forkedTranslationArtifactVersion.translationChapters.forEach(translationChapter => {
|
||||||
|
translationChapter.translationChunks.forEach(translationChunk => {
|
||||||
|
if (existingTranslation[translationChunk.chunkId]) {
|
||||||
|
t.push({
|
||||||
|
translationChunkId: translationChunk.id,
|
||||||
|
creatorId: existingTranslation[translationChunk.chunkId].creatorId,
|
||||||
|
text: existingTranslation[translationChunk.chunkId].text,
|
||||||
|
translationArtifactVersionId: forkedTranslationArtifactVersion.id
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
await db.Translation.bulkCreate(t)
|
||||||
|
return response.redirect(`/translate/${forkedTranslationArtifactVersion.id}`)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
next()
|
||||||
}
|
}
|
||||||
} else {
|
}).catch(error => {
|
||||||
next()
|
next(error)
|
||||||
}
|
})
|
||||||
}).catch(error => {
|
}
|
||||||
next(error)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
router.route('/e/:id')
|
router.route('/e/:id')
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ module.exports = function (options) {
|
|||||||
association: db.Entity.EntityUsers,
|
association: db.Entity.EntityUsers,
|
||||||
required: true,
|
required: true,
|
||||||
where: {
|
where: {
|
||||||
userId: request.user.id
|
userId: request.user?.id ?? null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -60,7 +60,7 @@ module.exports = function (options) {
|
|||||||
association: db.Entity.EntityUsers,
|
association: db.Entity.EntityUsers,
|
||||||
required: true,
|
required: true,
|
||||||
where: {
|
where: {
|
||||||
userId: request.user.id
|
userId: request.user?.id ?? null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -7,7 +7,35 @@ module.exports = function (options) {
|
|||||||
|
|
||||||
router.route('/')
|
router.route('/')
|
||||||
.get(function(request, response, next) {
|
.get(function(request, response, next) {
|
||||||
db.Project.findAll()
|
db.Project.findAll({
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.Project.Owner,
|
||||||
|
required: true,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.Owner.OwnerEntities,
|
||||||
|
required: true,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.OwnerEntity.Entity,
|
||||||
|
required: true,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.Entity.EntityUsers,
|
||||||
|
required: true,
|
||||||
|
where: {
|
||||||
|
userId: request.user?.id ?? null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
.then(projects => {
|
.then(projects => {
|
||||||
response.display("projects", {
|
response.display("projects", {
|
||||||
user: request.user,
|
user: request.user,
|
||||||
@@ -51,6 +79,31 @@ module.exports = function (options) {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
association: db.Project.Owner,
|
||||||
|
required: true,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.Owner.OwnerEntities,
|
||||||
|
required: true,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.OwnerEntity.Entity,
|
||||||
|
required: true,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.Entity.EntityUsers,
|
||||||
|
required: true,
|
||||||
|
where: {
|
||||||
|
userId: request.user?.id ?? null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}).then(project => {
|
}).then(project => {
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ module.exports = function (options) {
|
|||||||
association: db.Entity.EntityUsers,
|
association: db.Entity.EntityUsers,
|
||||||
required: false,
|
required: false,
|
||||||
where: {
|
where: {
|
||||||
userId: request.user.id
|
userId: request.user?.id ?? null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -74,7 +74,7 @@ module.exports = function (options) {
|
|||||||
association: db.Entity.EntityUsers,
|
association: db.Entity.EntityUsers,
|
||||||
required: false,
|
required: false,
|
||||||
where: {
|
where: {
|
||||||
userId: request.user.id
|
userId: request.user?.id ?? null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -374,7 +374,7 @@ module.exports = function (options) {
|
|||||||
association: db.Entity.EntityUsers,
|
association: db.Entity.EntityUsers,
|
||||||
required: true,
|
required: true,
|
||||||
where: {
|
where: {
|
||||||
userId: request.user.id
|
userId: request.user?.id ?? null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -480,7 +480,7 @@ module.exports = function (options) {
|
|||||||
association: db.Entity.EntityUsers,
|
association: db.Entity.EntityUsers,
|
||||||
required: true,
|
required: true,
|
||||||
where: {
|
where: {
|
||||||
userId: request.user.id
|
userId: request.user?.id ?? null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -542,7 +542,7 @@ module.exports = function (options) {
|
|||||||
association: db.Entity.EntityUsers,
|
association: db.Entity.EntityUsers,
|
||||||
required: true,
|
required: true,
|
||||||
where: {
|
where: {
|
||||||
userId: request.user.id
|
userId: request.user?.id ?? nulls
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -605,7 +605,7 @@ module.exports = function (options) {
|
|||||||
association: db.Entity.EntityUsers,
|
association: db.Entity.EntityUsers,
|
||||||
required: true,
|
required: true,
|
||||||
where: {
|
where: {
|
||||||
userId: request.user.id
|
userId: request.user?.id ?? null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ module.exports = function (options) {
|
|||||||
association: db.Entity.EntityUsers,
|
association: db.Entity.EntityUsers,
|
||||||
required: false,
|
required: false,
|
||||||
where: {
|
where: {
|
||||||
userId: request.user.id
|
userId: request.user?.id ?? null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -97,7 +97,7 @@ module.exports = function (options) {
|
|||||||
association: db.Entity.EntityUsers,
|
association: db.Entity.EntityUsers,
|
||||||
required: true,
|
required: true,
|
||||||
where: {
|
where: {
|
||||||
userId: request.user.id
|
userId: request.user?.id ?? null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -153,7 +153,7 @@ module.exports = function (options) {
|
|||||||
association: db.Entity.EntityUsers,
|
association: db.Entity.EntityUsers,
|
||||||
required: true,
|
required: true,
|
||||||
where: {
|
where: {
|
||||||
userId: request.user.id
|
userId: request.user?.id ?? null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user