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