Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Feat/wdfGrantLetter #4771

Open
wants to merge 31 commits into
base: test
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3d69a54
adds code outline for adobe sign token fetching function
Mar 28, 2022
0369b21
adds scaffold for creating adobe sign agreements
Mar 28, 2022
475d09f
adds national org boolean to determine the grant letter template:
Mar 29, 2022
bbaa752
removes generateToken function as using key instead
Mar 29, 2022
3275c8e
adds adobe sign function to query an agreement by the ID
Mar 29, 2022
7a6a943
renames utils folder and throws errors so they can be handled at rout…
Mar 29, 2022
ce86fb9
adds config details required for echo sign
Mar 29, 2022
a3ac11e
adds migrations and model for db setup
Mar 29, 2022
6bb9663
renames folder to match db table name and removes unsed variable for …
Mar 29, 2022
bcf617d
fix path in tests
Mar 29, 2022
21dc045
updates variables passed and tests associated with updates
Mar 30, 2022
1e386ff
removes forename from adobe sign payload
Mar 30, 2022
b1e49d3
adds endpoint routing for wdf grant letters
Mar 30, 2022
0df0dc6
adds model for fetching WDF data
Mar 30, 2022
b4d4bb6
adds route handler for generating WDF grant letter
Mar 30, 2022
21bfebc
update the migration and model
Zuhal-Ayob Mar 31, 2022
027798b
save aggrement data
Zuhal-Ayob Mar 31, 2022
0cda855
refactors to have the method within the model to allow easier stubbin…
Mar 31, 2022
200c139
updates test with method and url
Apr 1, 2022
1ca898e
fixes test issue with stub
Apr 1, 2022
80ed878
updates db model and migration
Apr 1, 2022
700b7b5
saves the Adobe Sign status rather than mapping as status is not alwa…
Apr 1, 2022
e1aa307
get status from echoSign
Zuhal-Ayob Apr 1, 2022
b89076d
fix merge conflicts
Zuhal-Ayob Apr 1, 2022
0e8c872
move the files to the right place
Zuhal-Ayob Apr 1, 2022
9edd46d
updates tests following folder restructure
Apr 1, 2022
763a0ec
removes complete date from migrations and drops type on down migration
Apr 1, 2022
38b8551
changes date sent to date created due to adobe sign meta data available
Apr 4, 2022
64bbe0e
get the echoSign status and save it to the database after comparing w…
Zuhal-Ayob Apr 4, 2022
52235ff
updated with brunch
Zuhal-Ayob Apr 4, 2022
0e58b43
fixes broken tests due to conflict resolution
Apr 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions migrations/20220329140351-createDevelopmentFundGrantsTable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use strict';

module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable(
'DevelopmentFundGrants',
{
AgreementID: {
type: Sequelize.STRING,
allowNull: false,
primaryKey: true,
},
EstablishmentID: {
type: Sequelize.INTEGER,
references: {
model: {
tableName: 'Establishment',
schema: 'cqc',
},
key: 'EstablishmentID',
},
unique: true,
},
SignStatus: {
type: Sequelize.STRING(36),
allowNull: false,
},
Receiver: {
type: Sequelize.STRING(100),
allowNull: false,
},
DateSent: {
type: Sequelize.DATE,
allowNull: false,
default: Sequelize.NOW,
},
DateCompleted: {
type: Sequelize.DATE,
allowNull: true,
default: null,
},
},
{
schema: 'cqc',
},
);
},

down: (queryInterface, Sequelize) => {
return queryInterface.dropTable({
tableName: 'DevelopmentFundGrants',
schema: 'cqc',
});
},
};
44 changes: 30 additions & 14 deletions server/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,6 @@ const config = convict({
},
},

redis: {
url: {
doc: 'The URI to redirect users to the Redis',
format: String,
default: 'redis://localhost:6379',
},
serviceName: {
doc: 'Name of VCAP Service for Redis',
format: String,
default: 'Unknown',
env: 'REDIS_SERVICE_NAME',
},
},

notify: {
key: {
doc: 'The gov.uk notify key',
Expand Down Expand Up @@ -629,6 +615,36 @@ const config = convict({
env: 'REDIS_SERVICE_NAME',
},
},
adobeSign: {
apiBaseUrl: {
doc: 'The base URL for adobe sign API calls',
format: String,
default: 'https://api.eu2.adobesign.com:443',
},
directAccessDoc: {
doc: 'ID of direct access template',
format: String,
default:
{
production: 'prodDocIdHere',
}[this.env] || 'CBJCHBCAABAAWaloyEh2SuKJ7y-NFqAe7CwlouyqBFjj',
},
nationalOrgDoc: {
doc: 'ID of national organisation template',
format: String,
default:
{
production: 'prodDocIdHere',
}[this.env] || 'CBJCHBCAABAAHk5Czg1lz5LNbIlbRgvEnc7twleqy98A',
},
apiKey: {
doc: 'Adobe Sign API Key',
format: String,
default: '',
sensitive: true,
env: 'ADOBE_SIGN_KEY',
},
},
});

// Load environment dependent configuration
Expand Down
50 changes: 50 additions & 0 deletions server/models/developmentFundGrants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict';

module.exports = function (sequelize, DataTypes) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function exports has 45 lines of code (exceeds 25 allowed). Consider refactoring.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function exports has 49 lines of code (exceeds 25 allowed). Consider refactoring.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function exports has 52 lines of code (exceeds 25 allowed). Consider refactoring.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function exports has 62 lines of code (exceeds 25 allowed). Consider refactoring.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function exports has 82 lines of code (exceeds 25 allowed). Consider refactoring.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function exports has 77 lines of code (exceeds 25 allowed). Consider refactoring.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function exports has 97 lines of code (exceeds 25 allowed). Consider refactoring.

const DevelopmentFundGrants = sequelize.define(
'DevelopmentFundGrants',
{
AgreementID: {
type: DataTypes.STRING,
allowNull: false,
primaryKey: true,
},
EstablishmentID: {
type: DataTypes.INTEGER,
references: {
model: {
tableName: 'Establishment',
schema: 'cqc',
},
key: 'EstablishmentID',
},
unique: true,
},
SignStatus: {
type: DataTypes.STRING(36),
allowNull: false,
},
Receiver: {
type: DataTypes.STRING(100),
allowNull: false,
},
DateSent: {
type: DataTypes.DATE,
allowNull: false,
default: sequelize.NOW,
},
DateCompleted: {
type: DataTypes.DATE,
allowNull: true,
default: null,
},
},
{
tableName: 'DevelopmentFundGrants',
createdAt: false,
updatedAt: false,
},
);

return DevelopmentFundGrants;
};
9 changes: 9 additions & 0 deletions server/models/establishment.js
Original file line number Diff line number Diff line change
Expand Up @@ -1931,5 +1931,14 @@ module.exports = function (sequelize, DataTypes) {
});
};

Establishment.getWDFClaimData = async function (establishmentId) {
return await this.findOne({
attributes: ['NameValue', 'address1', 'town', 'county', 'postcode', 'IsNationalOrg'],
where: {
id: establishmentId,
},
});
};

return Establishment;
};
86 changes: 86 additions & 0 deletions server/routes/wdf/developmentFundGrants/adobeSign/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
const config = require('../../../../config/config');
const axios = require('axios');

const adobeSignBaseUrl = config.get('adobeSign.apiBaseUrl');
const adobeApiKey = config.get('adobeSign.apiKey');

module.exports.createAgreement = async (claimData) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function createAgreement has 64 lines of code (exceeds 25 allowed). Consider refactoring.

const { name, email, address, town, county, postcode, organisation, isNationalOrg } = claimData;
const body = {
fileInfos: [
{
libraryDocumentId: config.get(`${isNationalOrg ? 'adobeSign.nationalOrgDoc' : 'adobeSign.directAccessDoc'}`),
},
],
participantSetsInfo: [
{
role: 'SIGNER',
order: 1,
memberInfos: [
{
email,
name,
},
],
},
],
signatureType: 'ESIGN',
state: 'IN_PROCESS',
status: 'OUT_FOR_SIGNATURE',
name: 'Workplace Development Fund Grant Letter', // title of the agreement
mergeFieldInfo: [
{
defaultValue: name,
fieldName: 'full_name',
},
{
defaultValue: organisation,
fieldName: 'organisation',
},
{
defaultValue: address,
fieldName: 'address',
},
{
defaultValue: town,
fieldName: 'town',
},
{
defaultValue: county,
fieldName: 'county',
},
{
defaultValue: postcode,
fieldName: 'postcode',
},
{
defaultValue: 'contractNumber',
fieldName: 'contract_number',
},
],
};

return axios
.post(`${adobeSignBaseUrl}/api/rest/v6/agreements`, body, {
headers: {
Authorization: `Bearer ${adobeApiKey}`,
},
})
.then(({ data }) => data)
.catch((err) => {
throw err;
});
};

module.exports.queryAgreementStatus = async (agreementId) => {
return axios
.get(`${adobeSignBaseUrl}/api/rest/v6/agreements/${agreementId}`, {
headers: {
Authorization: `Bearer ${adobeApiKey}`,
},
})
.then(({ data }) => data)
.catch((err) => {
throw err;
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const models = require('../../../models');
const { createAgreement } = require('./adobeSign');

const generateDevelopmentFundGrantLetter = async (req, res, next) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function generateDevelopmentFundGrantLetter has 32 lines of code (exceeds 25 allowed). Consider refactoring.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function generateDevelopmentFundGrantLetter has 28 lines of code (exceeds 25 allowed). Consider refactoring.

try {
const { establishmentId, name, email } = req.body;
const { NameValue, address1, town, county, postcode, IsNationalOrg } = await models.establishment.getWDFClaimData(
establishmentId,
);
// additional fields needed - funding_amount, grant_reference
const { id } = await createAgreement({
name,
email,
organisation: NameValue,
address: address1,
town,
county,
postcode,
isNationalOrg: IsNationalOrg,
});
// save to DB - success then continue, else cancel

return res.status(201).json({ id });
} catch (err) {
return next(Error('unable to create agreement'));
}
};

module.exports.generateDevelopmentFundGrantLetter = generateDevelopmentFundGrantLetter;
19 changes: 19 additions & 0 deletions server/routes/wdf/developmentFundGrants/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const router = require('express').Router();
const { queryAgreementStatus } = require('./adobeSign');

router.post('/agreements', require('./generateDevelopmentFundGrantLetter'));

router.get('/agreements/:agreementId', async (req, res, next) => {
const { agreementId } = req.params;
try {
const agreementStatus = await queryAgreementStatus(agreementId);

// store update status in db

return res.json(agreementStatus);
} catch (err) {
return next(Error(`unable to query agreement with ID ${agreementId}`));
}
});

module.exports = router;
2 changes: 2 additions & 0 deletions server/routes/wdf/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ const express = require('express');
const router = express.Router();

const DisbursementFile = require('./disbursementFile');
const DevelopmentFund = require('./developmentFundGrants');

router.use('/disbursementFile', DisbursementFile);
router.use('/developmentFund', DevelopmentFund);

module.exports = router;
Loading