Create campaign for project
This commit is contained in:
@@ -6,9 +6,16 @@ module.exports = function (options) {
|
|||||||
|
|
||||||
router.route('/')
|
router.route('/')
|
||||||
.get(function(request, response, next) {
|
.get(function(request, response, next) {
|
||||||
response.display("campaigns", {
|
db.Campaign.findAll({
|
||||||
user: request.user,
|
|
||||||
pageTitle: "Campaign - Mantra"
|
}).then(campaigns => {
|
||||||
|
response.display("campaigns", {
|
||||||
|
user: request.user,
|
||||||
|
pageTitle: "Campaign - Mantra",
|
||||||
|
campaigns: campaigns
|
||||||
|
})
|
||||||
|
}).catch(error => {
|
||||||
|
next(error)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -284,6 +284,23 @@ module.exports = function (options) {
|
|||||||
{
|
{
|
||||||
association: db.Project.Campaign,
|
association: db.Project.Campaign,
|
||||||
required: true
|
required: true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}).then(project => {
|
||||||
|
if (project) {
|
||||||
|
response.redirect(`/campaigns/${project.campaign.id}`)
|
||||||
|
} else {
|
||||||
|
response.redirect(`/projects/${request.params.id}/campaign/create`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
router.route('/:id/campaign/create')
|
||||||
|
.get(function(request, response, next) {
|
||||||
|
db.Project.findByPk(request.params.id, {
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.Project.Campaign,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
association: db.Project.ProjectArtifactVersions,
|
association: db.Project.ProjectArtifactVersions,
|
||||||
@@ -317,23 +334,6 @@ module.exports = function (options) {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}).then(project => {
|
|
||||||
if (project) {
|
|
||||||
response.redirect(`/campaigns/${project.campaign.id}`)
|
|
||||||
} else {
|
|
||||||
response.redirect(`/projects/${request.params.id}/campaign/create`)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
router.route('/:id/campaign/create')
|
|
||||||
.get(function(request, response, next) {
|
|
||||||
db.Project.findByPk(request.params.id, {
|
|
||||||
include: [
|
|
||||||
{
|
|
||||||
association: db.Project.Campaign,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}).then(project => {
|
}).then(project => {
|
||||||
if (project) {
|
if (project) {
|
||||||
if (project.campaign) {
|
if (project.campaign) {
|
||||||
@@ -356,6 +356,82 @@ module.exports = function (options) {
|
|||||||
next(error)
|
next(error)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
.post(function(request, response, next) {
|
||||||
|
db.Project.findByPk(request.params.id, {
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.Project.Campaign,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
association: db.Project.ProjectArtifactVersions,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.ProjectArtifactVersion.ArtifactVersion,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.ArtifactVersion.Artifact
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
association: db.Project.ProjectTranslationArtifactVersions,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.ProjectTranslationArtifactVersion.TranslationArtifactVersion,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.TranslationArtifactVersion.ArtifactVersion,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.ArtifactVersion.Artifact
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}).then(async (project) => {
|
||||||
|
if (project) {
|
||||||
|
if (project.campaign) {
|
||||||
|
response.redirect(`/campaigns/${project.campaign.id}`)
|
||||||
|
} else {
|
||||||
|
const translationArtifactVersionCampaigns = project.projectTranslationArtifactVersions.map(projectTranslationArtifactVersion => {
|
||||||
|
return {
|
||||||
|
translationArtifactVersionId: projectTranslationArtifactVersion.translationArtifactVersionId,
|
||||||
|
entityId: request.user.individualEntityUser.entityUser.entityId,
|
||||||
|
satoshis: request.body.satoshis
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const campaign = await db.Campaign.create({
|
||||||
|
name: request.body.name,
|
||||||
|
description: request.body.description,
|
||||||
|
// defaultSatoshis: [request.body.satoshis].flat()[0],
|
||||||
|
defaultSatoshis: request.body.satoshis,
|
||||||
|
entityId: request.user.individualEntityUser.entityUser.entityId,
|
||||||
|
translationArtifactVersionCampaigns: translationArtifactVersionCampaigns
|
||||||
|
}, {
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.Campaign.TranslationArtifactVersionCampaigns
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
response.redirect(`/campaigns/${campaign.id}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
next(error)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
router.route('/:id/spreadsheet')
|
router.route('/:id/spreadsheet')
|
||||||
.post(function(request, response, next) {
|
.post(function(request, response, next) {
|
||||||
|
|||||||
@@ -3,4 +3,14 @@ extend templates/layout.pug
|
|||||||
block content
|
block content
|
||||||
.container
|
.container
|
||||||
.center
|
.center
|
||||||
h1 Campaigns
|
h1 Campaigns
|
||||||
|
|
||||||
|
if campaigns.length == 0
|
||||||
|
p.flow-text No campaigns found
|
||||||
|
else
|
||||||
|
.row
|
||||||
|
each campaign in campaigns
|
||||||
|
.col.s12
|
||||||
|
a(href=`/campaigns/${campaign.id}`)
|
||||||
|
.card-panel
|
||||||
|
p.flow-text= campaign.name
|
||||||
Reference in New Issue
Block a user