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