Track creator
This commit is contained in:
2
package-lock.json
generated
2
package-lock.json
generated
@@ -25,7 +25,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"../mantra-db-models": {
|
"../mantra-db-models": {
|
||||||
"version": "0.0.8",
|
"version": "0.0.9",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bcrypt": "^5.0.1",
|
"bcrypt": "^5.0.1",
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ module.exports = function (options) {
|
|||||||
licenseId: "copyright",
|
licenseId: "copyright",
|
||||||
artifactVersions: [
|
artifactVersions: [
|
||||||
{
|
{
|
||||||
|
creatorId: request.user.id,
|
||||||
tag: request.body.version
|
tag: request.body.version
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -137,6 +137,10 @@ module.exports = function (options) {
|
|||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
association: db.Project.ProjectArtifactVersions,
|
association: db.Project.ProjectArtifactVersions,
|
||||||
|
where: {
|
||||||
|
artifactVersionId: request.body.artifactVersionId
|
||||||
|
},
|
||||||
|
required: false,
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
association: db.ProjectArtifactVersion.ArtifactVersion,
|
association: db.ProjectArtifactVersion.ArtifactVersion,
|
||||||
@@ -169,24 +173,38 @@ module.exports = function (options) {
|
|||||||
]
|
]
|
||||||
}).then(async (project) => {
|
}).then(async (project) => {
|
||||||
if (project) {
|
if (project) {
|
||||||
// TODO: Fi
|
// TODO: check if project.artifactVersions.length == 0
|
||||||
const artifactVersion = await db.ArtifactVersion.findByPk(request.body.artifactVersionId, {
|
const artifactVersion = await db.ArtifactVersion.findByPk(request.body.artifactVersionId, {
|
||||||
// Narrow it down to artifacts this user has admin ownership off...,
|
// Narrow it down to artifacts this user has admin ownership off...,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.ArtifactVersion.TranslationArtifactVersions
|
||||||
|
}
|
||||||
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
if (artifactVersion) {
|
if (artifactVersion) {
|
||||||
const projectArtifactVersion = db.ProjectArtifactVersion.create({
|
const projectArtifactVersion = await getProjectArtifactVersion(request.user.id, project, artifactVersion)
|
||||||
creatorId: request.user.id,
|
// Bulk create the project translations...
|
||||||
projectId: project.id,
|
const projectTranslationArtifactVersionObjects = artifactVersion.translationArtifactVersions.filter(translationArtifactVersion => {
|
||||||
artifactVersionId: artifactVersion.id
|
// filter out translations already added to the project...
|
||||||
|
return !project.projectTranslationArtifactVersions.some(projectTranslationArtifactVersions => {
|
||||||
|
return projectTranslationArtifactVersions.translationArtifactVersionId == translationArtifactVersion.id
|
||||||
|
})
|
||||||
|
}).map(translationArtifactVersion => {
|
||||||
|
return {
|
||||||
|
creatorId: request.user.id,
|
||||||
|
projectId: project.id,
|
||||||
|
translationArtifactVersionId: translationArtifactVersion.id,
|
||||||
|
projectArtifactVersionId: projectArtifactVersion.id
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
if (projectTranslationArtifactVersionObjects.length > 0) {
|
||||||
|
const projectTranslationArtifactVersions = await db.ProjectTranslationArtifactVersion.bulkCreate(projectTranslationArtifactVersionObjects)
|
||||||
|
}
|
||||||
|
|
||||||
response.redirect(`/projects/${project.id}`)
|
response.redirect(`/projects/${project.id}`)
|
||||||
} else {
|
|
||||||
response.redirect(`/projects/${project.id}/add-artifact`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
@@ -404,6 +422,7 @@ module.exports = function (options) {
|
|||||||
} else {
|
} else {
|
||||||
const translationArtifactVersionCampaigns = project.projectTranslationArtifactVersions.map(projectTranslationArtifactVersion => {
|
const translationArtifactVersionCampaigns = project.projectTranslationArtifactVersions.map(projectTranslationArtifactVersion => {
|
||||||
return {
|
return {
|
||||||
|
creatorId: request.user.id,
|
||||||
translationArtifactVersionId: projectTranslationArtifactVersion.translationArtifactVersionId,
|
translationArtifactVersionId: projectTranslationArtifactVersion.translationArtifactVersionId,
|
||||||
entityId: request.user.individualEntityUser.entityUser.entityId,
|
entityId: request.user.individualEntityUser.entityUser.entityId,
|
||||||
satoshis: request.body.satoshis
|
satoshis: request.body.satoshis
|
||||||
@@ -448,14 +467,17 @@ module.exports = function (options) {
|
|||||||
// TODO: require translationArtifactVersions in ProjectArtifactVersion
|
// TODO: require translationArtifactVersions in ProjectArtifactVersion
|
||||||
{
|
{
|
||||||
association: db.TranslationArtifactVersion.ProjectTranslationArtifactVersions,
|
association: db.TranslationArtifactVersion.ProjectTranslationArtifactVersions,
|
||||||
|
required: true,
|
||||||
where: {
|
where: {
|
||||||
projectId: request.params.id
|
projectId: request.params.id
|
||||||
},
|
},
|
||||||
required: true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
association: db.TranslationArtifactVersion.ArtifactVersion,
|
association: db.TranslationArtifactVersion.ArtifactVersion,
|
||||||
include: [
|
include: [
|
||||||
|
{
|
||||||
|
association: db.ArtifactVersion.ProjectArtifactVersions
|
||||||
|
},
|
||||||
{
|
{
|
||||||
association: db.ArtifactVersion.Artifact,
|
association: db.ArtifactVersion.Artifact,
|
||||||
include: [
|
include: [
|
||||||
@@ -593,7 +615,11 @@ module.exports = function (options) {
|
|||||||
worksheet.row(3).setHeight(5)
|
worksheet.row(3).setHeight(5)
|
||||||
worksheet.row(5).setHeight(5)
|
worksheet.row(5).setHeight(5)
|
||||||
})
|
})
|
||||||
workbook.write(`${project.name}.xlsx`, response);
|
if (translationArtifactVersions.length > 0) {
|
||||||
|
workbook.write(`${project.name}.xlsx`, response);
|
||||||
|
} else {
|
||||||
|
response.redirect(`/projects/${request.params.id}`)
|
||||||
|
}
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
next(error)
|
next(error)
|
||||||
})
|
})
|
||||||
@@ -604,5 +630,17 @@ module.exports = function (options) {
|
|||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const getProjectArtifactVersion = (userId, project, artifactVersion) => {
|
||||||
|
if (project.projectArtifactVersions.length == 0) {
|
||||||
|
return db.ProjectArtifactVersion.create({
|
||||||
|
creatorId: userId,
|
||||||
|
projectId: project.id,
|
||||||
|
artifactVersionId: artifactVersion.id
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
return project.projectArtifactVersions[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return router;
|
return router;
|
||||||
};
|
};
|
||||||
@@ -253,6 +253,7 @@ module.exports = function (options) {
|
|||||||
creatorId: request.user.id,
|
creatorId: request.user.id,
|
||||||
translationArtifactVersionId: translationArtifactVersion.id,
|
translationArtifactVersionId: translationArtifactVersion.id,
|
||||||
artifact: {
|
artifact: {
|
||||||
|
creatorId: request.user.id,
|
||||||
name: translationArtifactVersion.name + translationArtifactVersion.artifactVersion.artifact.name,
|
name: translationArtifactVersion.name + translationArtifactVersion.artifactVersion.artifact.name,
|
||||||
url: `/translate/${request.params.id}`,
|
url: `/translate/${request.params.id}`,
|
||||||
dialectId: translationArtifactVersion.dialectId,
|
dialectId: translationArtifactVersion.dialectId,
|
||||||
@@ -423,6 +424,7 @@ module.exports = function (options) {
|
|||||||
entityId: request.user.individualEntityUser.entityUser.entityId,
|
entityId: request.user.individualEntityUser.entityUser.entityId,
|
||||||
translationArtifactVersionCampaigns: [
|
translationArtifactVersionCampaigns: [
|
||||||
{
|
{
|
||||||
|
creatorId: request.user.id,
|
||||||
translationArtifactVersionId: translationArtifactVersion.id,
|
translationArtifactVersionId: translationArtifactVersion.id,
|
||||||
entityId: request.user.individualEntityUser.entityUser.entityId,
|
entityId: request.user.individualEntityUser.entityUser.entityId,
|
||||||
satoshis: request.body.satoshis
|
satoshis: request.body.satoshis
|
||||||
@@ -545,6 +547,7 @@ module.exports = function (options) {
|
|||||||
entityId: request.user.individualEntityUser.entityUser.entityId,
|
entityId: request.user.individualEntityUser.entityUser.entityId,
|
||||||
translationArtifactVersionPledges: [
|
translationArtifactVersionPledges: [
|
||||||
{
|
{
|
||||||
|
creatorId: request.user.id,
|
||||||
translationArtifactVersionId: translationArtifactVersion.id,
|
translationArtifactVersionId: translationArtifactVersion.id,
|
||||||
entityId: request.user.individualEntityUser.entityUser.entityId,
|
entityId: request.user.individualEntityUser.entityUser.entityId,
|
||||||
satoshis: request.body.satoshis
|
satoshis: request.body.satoshis
|
||||||
|
|||||||
@@ -95,7 +95,8 @@ module.exports = function (options) {
|
|||||||
artifactVersionId: artifactVersion.id,
|
artifactVersionId: artifactVersion.id,
|
||||||
chunks: chunks.map((chunk,index) => {
|
chunks: chunks.map((chunk,index) => {
|
||||||
return {
|
return {
|
||||||
text: chunk,
|
creatorId: request.user.id,
|
||||||
|
text: chunk.trim(),
|
||||||
index: index
|
index: index
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user