From 334e3ecade72cf5cc403a2bd85a522aa8b5124a1 Mon Sep 17 00:00:00 2001 From: Richard Pentecost Date: Thu, 22 Feb 2024 15:03:16 +0000 Subject: [PATCH] clean up old code for adding evidence documents for investment projects --- .../apps/evidence/controllers/create.js | 37 ------------------- .../apps/evidence/controllers/index.js | 5 --- src/apps/investments/apps/evidence/index.js | 6 --- src/apps/investments/apps/evidence/labels.js | 10 ----- .../apps/evidence/macros/evidence-form.js | 25 ------------- .../apps/evidence/macros/fields.js | 34 ----------------- .../investments/apps/evidence/macros/index.js | 5 --- src/apps/investments/apps/evidence/router.js | 7 ---- .../investments/apps/evidence/transformers.js | 25 ------------- .../apps/evidence/views/create.njk | 5 --- src/apps/investments/middleware/evidence.js | 27 -------------- src/apps/investments/router-projects.js | 12 ------ 12 files changed, 198 deletions(-) delete mode 100644 src/apps/investments/apps/evidence/controllers/create.js delete mode 100644 src/apps/investments/apps/evidence/controllers/index.js delete mode 100644 src/apps/investments/apps/evidence/index.js delete mode 100644 src/apps/investments/apps/evidence/labels.js delete mode 100644 src/apps/investments/apps/evidence/macros/evidence-form.js delete mode 100644 src/apps/investments/apps/evidence/macros/fields.js delete mode 100644 src/apps/investments/apps/evidence/macros/index.js delete mode 100644 src/apps/investments/apps/evidence/router.js delete mode 100644 src/apps/investments/apps/evidence/transformers.js delete mode 100644 src/apps/investments/apps/evidence/views/create.njk delete mode 100644 src/apps/investments/middleware/evidence.js diff --git a/src/apps/investments/apps/evidence/controllers/create.js b/src/apps/investments/apps/evidence/controllers/create.js deleted file mode 100644 index ec68d954bc3..00000000000 --- a/src/apps/investments/apps/evidence/controllers/create.js +++ /dev/null @@ -1,37 +0,0 @@ -/* eslint camelcase: 0 */ -const { assign, get } = require('lodash') - -const { buildFormWithStateAndErrors } = require('../../../../builders') -const { getOptions } = require('../../../../../lib/options') -const { evidenceForm } = require('../macros/index') - -async function renderAddEvidence(req, res) { - const investment = get(res.locals, 'investment.id') - const tags = await getOptions(req, 'evidence-tag') - - const addEvidenceForm = buildFormWithStateAndErrors( - evidenceForm( - assign({}, res.locals.options, res.locals.conditions, { - returnLink: res.locals.returnLink, - returnText: 'Cancel', - buttonText: 'Upload', - tags, - hiddenFields: { - investment, - }, - }) - ), - get(res.locals, 'form.errors.messages') - ) - - res - .breadcrumb('Add evidence') - .title('Add evidence') - .render('investments/apps/evidence/views/create', { - addEvidenceForm, - }) -} - -module.exports = { - renderAddEvidence, -} diff --git a/src/apps/investments/apps/evidence/controllers/index.js b/src/apps/investments/apps/evidence/controllers/index.js deleted file mode 100644 index 20fd45328d4..00000000000 --- a/src/apps/investments/apps/evidence/controllers/index.js +++ /dev/null @@ -1,5 +0,0 @@ -const { renderAddEvidence } = require('./create') - -module.exports = { - renderAddEvidence, -} diff --git a/src/apps/investments/apps/evidence/index.js b/src/apps/investments/apps/evidence/index.js deleted file mode 100644 index 6d2b900a94d..00000000000 --- a/src/apps/investments/apps/evidence/index.js +++ /dev/null @@ -1,6 +0,0 @@ -const router = require('./router') - -module.exports = { - mountpath: '/evidence', - router, -} diff --git a/src/apps/investments/apps/evidence/labels.js b/src/apps/investments/apps/evidence/labels.js deleted file mode 100644 index 5a70202ce05..00000000000 --- a/src/apps/investments/apps/evidence/labels.js +++ /dev/null @@ -1,10 +0,0 @@ -const evidenceForm = { - title: 'Title', - original_filename: 'Evidence file', - tags: 'Verification criteria', - comment: 'Comment', -} - -module.exports = { - evidenceForm, -} diff --git a/src/apps/investments/apps/evidence/macros/evidence-form.js b/src/apps/investments/apps/evidence/macros/evidence-form.js deleted file mode 100644 index 863a26670ef..00000000000 --- a/src/apps/investments/apps/evidence/macros/evidence-form.js +++ /dev/null @@ -1,25 +0,0 @@ -const { assign } = require('lodash') - -const labels = require('../labels') -const { tag, documentUpload, comment } = require('./fields') - -module.exports = function ({ - returnLink, - returnText, - buttonText, - hiddenFields, - tags = [], -}) { - return { - enctype: 'multipart/form-data', - returnLink, - returnText, - buttonText, - hiddenFields, - children: [documentUpload, tag(tags), comment].map((field) => { - return assign(field, { - label: labels.evidenceForm[field.name], - }) - }), - } -} diff --git a/src/apps/investments/apps/evidence/macros/fields.js b/src/apps/investments/apps/evidence/macros/fields.js deleted file mode 100644 index 11d2edb21e3..00000000000 --- a/src/apps/investments/apps/evidence/macros/fields.js +++ /dev/null @@ -1,34 +0,0 @@ -module.exports = { - tag(tags) { - return { - macroName: 'AddAnother', - buttonName: 'add_item', - label: 'Tags', - name: 'tags', - children: [ - { - macroName: 'MultipleChoiceField', - type: 'file', - label: 'Tag', - name: 'tags', - isLabelHidden: true, - initialOption: '-- Select criteria --', - options: tags, - }, - ], - } - }, - documentUpload: { - macroName: 'TextField', - type: 'file', - label: 'File', - name: 'original_filename', - isLabelHidden: true, - }, - comment: { - macroName: 'TextField', - type: 'textarea', - name: 'comment', - optional: true, - }, -} diff --git a/src/apps/investments/apps/evidence/macros/index.js b/src/apps/investments/apps/evidence/macros/index.js deleted file mode 100644 index 43ddcedb87a..00000000000 --- a/src/apps/investments/apps/evidence/macros/index.js +++ /dev/null @@ -1,5 +0,0 @@ -const evidenceForm = require('./evidence-form') - -module.exports = { - evidenceForm, -} diff --git a/src/apps/investments/apps/evidence/router.js b/src/apps/investments/apps/evidence/router.js deleted file mode 100644 index d22051ab849..00000000000 --- a/src/apps/investments/apps/evidence/router.js +++ /dev/null @@ -1,7 +0,0 @@ -const router = require('express').Router() - -const { renderAddEvidence } = require('./controllers') - -router.get('/evidence', renderAddEvidence) - -module.exports = router diff --git a/src/apps/investments/apps/evidence/transformers.js b/src/apps/investments/apps/evidence/transformers.js deleted file mode 100644 index 66aa286d1db..00000000000 --- a/src/apps/investments/apps/evidence/transformers.js +++ /dev/null @@ -1,25 +0,0 @@ -/* eslint-disable camelcase */ -const { compact, identity, map, pickBy } = require('lodash') - -function isTag(key) { - return key.search(/tag/i) !== -1 -} - -function transformedEvidenceTextFields(fields) { - const tags = compact( - map(fields, (value, key) => (isTag(key) ? fields[key] : null)) - ) - const comment = fields.comment - - return pickBy( - { - tags, - comment, - }, - identity - ) -} - -module.exports = { - transformedEvidenceTextFields, -} diff --git a/src/apps/investments/apps/evidence/views/create.njk b/src/apps/investments/apps/evidence/views/create.njk deleted file mode 100644 index 60f4af84ef7..00000000000 --- a/src/apps/investments/apps/evidence/views/create.njk +++ /dev/null @@ -1,5 +0,0 @@ -{% extends "_layouts/template.njk" %} - -{% block body_main_content %} - {{ Form(addEvidenceForm) }} -{% endblock %} diff --git a/src/apps/investments/middleware/evidence.js b/src/apps/investments/middleware/evidence.js deleted file mode 100644 index ee1f55bb7b9..00000000000 --- a/src/apps/investments/middleware/evidence.js +++ /dev/null @@ -1,27 +0,0 @@ -const { - transformedEvidenceTextFields, -} = require('../apps/evidence/transformers') - -function setEvidenceReturnUrl(req, res, next) { - const { projects } = res.locals.paths - const { investmentId } = req.params - res.locals.returnLink = `${projects}/${investmentId}/evidence` - next() -} - -function setEvidenceDocumentsOptions(req, res, next) { - res.locals.documents = { - collectTextFields: transformedEvidenceTextFields, - url: { - app: 'investment', - document: 'evidence-document', - }, - } - - next() -} - -module.exports = { - setEvidenceReturnUrl, - setEvidenceDocumentsOptions, -} diff --git a/src/apps/investments/router-projects.js b/src/apps/investments/router-projects.js index 0497e5abd04..d2123d986ea 100644 --- a/src/apps/investments/router-projects.js +++ b/src/apps/investments/router-projects.js @@ -13,15 +13,8 @@ const { shared } = require('./middleware') const { create, editHistory } = require('./controllers') -const { renderAddEvidence } = require('./apps/evidence/controllers/create') -const { postUpload } = require('../documents/middleware/upload') - const { setCompanyDetails } = require('./middleware/interactions') const { setPropositionsReturnUrl } = require('./middleware/propositions') -const { - setEvidenceReturnUrl, - setEvidenceDocumentsOptions, -} = require('./middleware/evidence') const interactionsRouter = require('../interactions/router.sub-app') const propositionsRouter = require('../propositions/router.sub-app') @@ -46,11 +39,6 @@ router.get('/create/:companyId?', create.start.renderCreatePage) // Add investment from Investments router.get('/create', create.start.renderCreatePage) -router - .route('/:investmentId/evidence/add-new') - .get(setEvidenceReturnUrl, renderAddEvidence) - .post(setEvidenceReturnUrl, setEvidenceDocumentsOptions, postUpload) - router.use( urls.investments.projects.interactions.index.route, setCompanyDetails,