Create pledge from translation
This commit is contained in:
@@ -6,10 +6,21 @@ module.exports = function (options) {
|
||||
|
||||
router.route('/')
|
||||
.get(function(request, response, next) {
|
||||
response.display("pledges", {
|
||||
user: request.user,
|
||||
pageTitle: "Library - Mantra"
|
||||
db.Pledge.findAll({
|
||||
}).then(pledges => {
|
||||
if (pledges) {
|
||||
response.display("pledges", {
|
||||
user: request.user,
|
||||
pageTitle: "Pledges - Mantra",
|
||||
pledges: pledges
|
||||
})
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
}).catch(error => {
|
||||
next(error)
|
||||
})
|
||||
|
||||
})
|
||||
return router;
|
||||
};
|
||||
@@ -318,7 +318,7 @@ module.exports = function (options) {
|
||||
})
|
||||
})
|
||||
|
||||
router.route('/:id/campaign')
|
||||
router.route('/:id/campaigns')
|
||||
.get(function(request, response, next) {
|
||||
db.TranslationArtifactVersion.findByPk(request.params.id, {
|
||||
include: [
|
||||
@@ -335,19 +335,19 @@ module.exports = function (options) {
|
||||
]
|
||||
}).then(translationArtifactVersion => {
|
||||
if (translationArtifactVersion) {
|
||||
if (translationArtifactVersion.translationArtifactVersionCampaings.length == 1) {
|
||||
response.redirect(`/campaigns/${translationArtifactVersion.translationArtifactVersionCampaings[0].campaignId}`)
|
||||
if (translationArtifactVersion.translationArtifactVersionCampaigns.length == 1) {
|
||||
response.redirect(`/campaigns/${translationArtifactVersion.translationArtifactVersionCampaigns[0].campaignId}`)
|
||||
} else {
|
||||
// TODO: Display translation artifact campaign...
|
||||
next()
|
||||
}
|
||||
} else {
|
||||
response.redirect(`/translate/${request.params.id}/campaign/create`)
|
||||
response.redirect(`/translate/${request.params.id}/campaigns/create`)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
router.route('/:id/campaign/create')
|
||||
router.route('/:id/campaigns/create')
|
||||
.get(function(request, response, next) {
|
||||
db.TranslationArtifactVersion.findByPk(request.params.id, {
|
||||
include: [
|
||||
@@ -442,5 +442,125 @@ module.exports = function (options) {
|
||||
})
|
||||
})
|
||||
|
||||
router.route('/:id/pledges')
|
||||
.get(function(request, response, next) {
|
||||
db.TranslationArtifactVersion.findByPk(request.params.id, {
|
||||
include: [
|
||||
{
|
||||
association: db.TranslationArtifactVersion.TranslationArtifactVersionPledges,
|
||||
required: true,
|
||||
include: [
|
||||
{
|
||||
association: db.TranslationArtifactVersionPledge.Pledge,
|
||||
required: true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}).then(translationArtifactVersion => {
|
||||
if (translationArtifactVersion) {
|
||||
if (translationArtifactVersion.translationArtifactVersionPledges.length == 1) {
|
||||
response.redirect(`/pledges/${translationArtifactVersion.translationArtifactVersionPledges[0].campaignId}`)
|
||||
} else {
|
||||
// TODO: Display translation artifact campaign...
|
||||
next()
|
||||
}
|
||||
} else {
|
||||
response.redirect(`/translate/${request.params.id}/pledges/create`)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
router.route('/:id/pledges/create')
|
||||
.get(function(request, response, next) {
|
||||
db.TranslationArtifactVersion.findByPk(request.params.id, {
|
||||
include: [
|
||||
{
|
||||
association: db.TranslationArtifactVersion.ArtifactVersion,
|
||||
include: [
|
||||
{
|
||||
association: db.ArtifactVersion.Artifact
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
association: db.TranslationArtifactVersion.TranslationArtifactVersionPledges,
|
||||
required: false,
|
||||
include: [
|
||||
{
|
||||
association: db.TranslationArtifactVersionPledge.Pledge,
|
||||
required: false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}).then(translationArtifactVersion => {
|
||||
if (translationArtifactVersion) {
|
||||
response.display("pledge-form", {
|
||||
user: request.user,
|
||||
pageTitle: "Pledge - Mantra",
|
||||
campaign: {
|
||||
name: `Pledge for ${translationArtifactVersion.name} translation of ${translationArtifactVersion.artifactVersion.artifact.name}`,
|
||||
},
|
||||
translationArtifactVersions: [translationArtifactVersion]
|
||||
})
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
}).catch(error => {
|
||||
next(error)
|
||||
})
|
||||
})
|
||||
.post(function(request, response, next) {
|
||||
db.TranslationArtifactVersion.findByPk(request.params.id, {
|
||||
include: [
|
||||
{
|
||||
association: db.TranslationArtifactVersion.ArtifactVersion,
|
||||
include: [
|
||||
{
|
||||
association: db.ArtifactVersion.Artifact
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
association: db.TranslationArtifactVersion.TranslationArtifactVersionPledges,
|
||||
required: false,
|
||||
include: [
|
||||
{
|
||||
association: db.TranslationArtifactVersionPledge.Pledge,
|
||||
required: false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}).then(async (translationArtifactVersion) => {
|
||||
if (translationArtifactVersion) {
|
||||
// TODO: Create campaign...
|
||||
const pledge = await db.Pledge.create({
|
||||
message: request.body.message,
|
||||
entityId: request.user.individualEntityUser.entityUser.entityId,
|
||||
translationArtifactVersionPledges: [
|
||||
{
|
||||
translationArtifactVersionId: translationArtifactVersion.id,
|
||||
entityId: request.user.individualEntityUser.entityUser.entityId,
|
||||
satoshis: request.body.satoshis
|
||||
}
|
||||
]
|
||||
}, {
|
||||
include: [
|
||||
{
|
||||
association: db.Pledge.TranslationArtifactVersionPledges
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
response.redirect(`/pledges/${pledge.id}`)
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
}).catch(error => {
|
||||
next(error)
|
||||
})
|
||||
})
|
||||
return router;
|
||||
};
|
||||
Reference in New Issue
Block a user