-
Notifications
You must be signed in to change notification settings - Fork 5
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
base: test
Are you sure you want to change the base?
WIP: Feat/wdfGrantLetter #4771
Changes from 15 commits
3d69a54
0369b21
475d09f
bbaa752
3275c8e
7a6a943
ce86fb9
a3ac11e
6bb9663
bcf617d
21dc045
1e386ff
b1e49d3
0df0dc6
b4d4bb6
21bfebc
027798b
0cda855
200c139
1ca898e
80ed878
700b7b5
e1aa307
b89076d
0e8c872
9edd46d
763a0ec
38b8551
64bbe0e
52235ff
0e58b43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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', | ||
}); | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
module.exports = function (sequelize, DataTypes) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function |
||
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; | ||
}; |
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) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function |
||
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) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function |
||
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; |
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; |
There was a problem hiding this comment.
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.