Add approval creation things
This commit is contained in:
@@ -53,6 +53,9 @@ module.exports = function (options) {
|
||||
forkedFromId: null
|
||||
},
|
||||
required: false
|
||||
},
|
||||
{
|
||||
association: db.ArtifactVersion.ArtifactVersionApproval
|
||||
}
|
||||
]
|
||||
}).then(artifactVersion => {
|
||||
@@ -379,5 +382,210 @@ module.exports = function (options) {
|
||||
})
|
||||
})
|
||||
|
||||
router.route('/:id/approval')
|
||||
.get(function(request, response, next) {
|
||||
db.ArtifactVersion.findByPk(request.params.id, {
|
||||
include: [
|
||||
{
|
||||
association: db.ArtifactVersion.Artifact,
|
||||
// required: true,
|
||||
include: [
|
||||
{
|
||||
association: db.Artifact.ArtifactApproval
|
||||
},
|
||||
{
|
||||
association: db.Artifact.Owner,
|
||||
// required: false,
|
||||
include: [
|
||||
{
|
||||
association: db.Owner.OwnerEntities,
|
||||
// required: true,
|
||||
include: [
|
||||
{
|
||||
association: db.OwnerEntity.Entity,
|
||||
// required: false,
|
||||
include: [
|
||||
{
|
||||
association: db.Entity.EntityUsers,
|
||||
required: false,
|
||||
where: {
|
||||
userId: request.user?.id ?? null
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
association: db.ArtifactVersion.Chapters
|
||||
},
|
||||
{
|
||||
association: db.ArtifactVersion.TranslationArtifactVersions,
|
||||
where: {
|
||||
backTranslationFromId: null,
|
||||
forkedFromId: null
|
||||
},
|
||||
required: false
|
||||
},
|
||||
{
|
||||
association: db.ArtifactVersion.ArtifactVersionApproval,
|
||||
required:true
|
||||
}
|
||||
]
|
||||
}).then(artifactVersion => {
|
||||
if (artifactVersion) {
|
||||
response.display("artifact-version-approval", {
|
||||
user: request.user,
|
||||
pageTitle: "Artifact - Mantra",
|
||||
artifactVersion: artifactVersion
|
||||
})
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
}).catch(error => {
|
||||
next(error)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
router.route('/:id/approval/add')
|
||||
.get(function(request, response, next) {
|
||||
db.ArtifactVersion.findByPk(request.params.id, {
|
||||
include: [
|
||||
{
|
||||
association: db.ArtifactVersion.Artifact,
|
||||
required: true,
|
||||
include: [
|
||||
{
|
||||
association: db.Artifact.ArtifactApproval,
|
||||
},
|
||||
{
|
||||
association: db.Artifact.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
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
association: db.ArtifactVersion.Chapters
|
||||
}
|
||||
]
|
||||
}).then(artifactVersion => {
|
||||
if (artifactVersion) {
|
||||
if (artifactVersion.artifactVersionApproval) {
|
||||
return response.redirect(`/v/${artifactVersion.id}/approval`)
|
||||
}
|
||||
response.display("artifact-version-approval-form", {
|
||||
user: request.user,
|
||||
pageTitle: "Approval - Mantra",
|
||||
artifactVersion: artifactVersion,
|
||||
artifactVersionApproval: {
|
||||
name: artifactVersion.artifact.artifactApproval?.name,
|
||||
description: artifactVersion.artifact.artifactApproval?.description,
|
||||
conditions: artifactVersion.artifact.artifactApproval?.conditions,
|
||||
satoshis: artifactVersion.artifact.artifactApproval?.satoshis,
|
||||
approvedAt: artifactVersion.artifact.artifactApproval?.approvedAt
|
||||
}
|
||||
})
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
|
||||
}).catch(error => {
|
||||
next(error)
|
||||
})
|
||||
})
|
||||
.post(function(request, response, next) {
|
||||
db.ArtifactVersion.findByPk(request.params.id, {
|
||||
include: [
|
||||
{
|
||||
association: db.ArtifactVersion.Artifact,
|
||||
required: true,
|
||||
include: [
|
||||
{
|
||||
association: db.Artifact.ArtifactApproval,
|
||||
},
|
||||
{
|
||||
association: db.Artifact.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
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
association: db.ArtifactVersion.Chapters
|
||||
}
|
||||
]
|
||||
}).then(async (artifactVersion) => {
|
||||
if (artifactVersion) {
|
||||
if (artifactVersion.artifactVersionApproval == null) {
|
||||
// Create artifactVersionApproval
|
||||
const satoshis = Number(request.body.satoshis) ? Number(request.body.satoshis) : null
|
||||
await db.ArtifactVersionApproval.create({
|
||||
name: request.body.name,
|
||||
type: 'umbrella',
|
||||
artifactVersionId: artifactVersion.id,
|
||||
description: request.body.description,
|
||||
conditions: request.body.conditions,
|
||||
satoshis: satoshis,
|
||||
creatorId: request.user.id,
|
||||
approvedAt: request.body.isApproved == 'on' ? new Date() : null
|
||||
})
|
||||
}
|
||||
|
||||
response.redirect(`/v/${artifactVersion.id}/approval`)
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
|
||||
}).catch(error => {
|
||||
next(error)
|
||||
})
|
||||
})
|
||||
|
||||
return router;
|
||||
};
|
||||
Reference in New Issue
Block a user