-
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 30 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,78 @@ | ||
'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', | ||
}, | ||
}, | ||
SignStatus: { | ||
type: Sequelize.ENUM, | ||
allowNull: false, | ||
values: [ | ||
'OUT_FOR_SIGNATURE', | ||
'OUT_FOR_DELIVERY', | ||
'OUT_FOR_ACCEPTANCE', | ||
'OUT_FOR_FORM_FILLING', | ||
'OUT_FOR_APPROVAL', | ||
'AUTHORING', | ||
'CANCELLED', | ||
'SIGNED', | ||
'APPROVED', | ||
'DELIVERED', | ||
'ACCEPTED', | ||
'FORM_FILLED', | ||
'EXPIRED', | ||
'ARCHIVED', | ||
'PREFILL', | ||
'WIDGET_WAITING_FOR_VERIFICATION', | ||
'DRAFT', | ||
'DOCUMENTS_NOT_YET_PROCESSED', | ||
'WAITING_FOR_FAXIN', | ||
'WAITING_FOR_VERIFICATION', | ||
'WAITING_FOR_NOTARIZATION', | ||
], | ||
}, | ||
ReceiverEmail: { | ||
type: Sequelize.STRING(320), | ||
allowNull: false, | ||
}, | ||
ReceiverName: { | ||
type: Sequelize.STRING(100), | ||
allowNull: false, | ||
}, | ||
DateCreated: { | ||
type: Sequelize.DATE, | ||
allowNull: false, | ||
default: Sequelize.NOW, | ||
}, | ||
}, | ||
{ | ||
schema: 'cqc', | ||
}, | ||
); | ||
}, | ||
|
||
down: async (queryInterface, Sequelize) => { | ||
await queryInterface.dropTable({ | ||
tableName: 'DevelopmentFundGrants', | ||
schema: 'cqc', | ||
}); | ||
|
||
return queryInterface.sequelize.query('DROP TYPE IF EXISTS cqc."enum_DevelopmentFundGrants_SignStatus";'); | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
'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', | ||
}, | ||
}, | ||
SignStatus: { | ||
type: DataTypes.ENUM, | ||
allowNull: false, | ||
values: [ | ||
'OUT_FOR_SIGNATURE', | ||
'OUT_FOR_DELIVERY', | ||
'OUT_FOR_ACCEPTANCE', | ||
'OUT_FOR_FORM_FILLING', | ||
'OUT_FOR_APPROVAL', | ||
'AUTHORING', | ||
'CANCELLED', | ||
'SIGNED', | ||
'APPROVED', | ||
'DELIVERED', | ||
'ACCEPTED', | ||
'FORM_FILLED', | ||
'EXPIRED', | ||
'ARCHIVED', | ||
'PREFILL', | ||
'WIDGET_WAITING_FOR_VERIFICATION', | ||
'DRAFT', | ||
'DOCUMENTS_NOT_YET_PROCESSED', | ||
'WAITING_FOR_FAXIN', | ||
'WAITING_FOR_VERIFICATION', | ||
'WAITING_FOR_NOTARIZATION', | ||
], | ||
}, | ||
ReceiverEmail: { | ||
type: DataTypes.STRING(320), | ||
allowNull: false, | ||
}, | ||
ReceiverName: { | ||
type: DataTypes.STRING(100), | ||
allowNull: false, | ||
}, | ||
DateCreated: { | ||
type: DataTypes.DATE, | ||
allowNull: false, | ||
default: sequelize.NOW, | ||
}, | ||
}, | ||
{ | ||
tableName: 'DevelopmentFundGrants', | ||
createdAt: false, | ||
updatedAt: false, | ||
schema: 'cqc', | ||
}, | ||
); | ||
|
||
DevelopmentFundGrants.saveWDFData = function (data) { | ||
return this.create({ | ||
AgreementID: data.agreementId, | ||
EstablishmentID: data.establishmentId, | ||
ReceiverEmail: data.email, | ||
ReceiverName: data.name, | ||
SignStatus: data.signStatus, | ||
DateCreated: data.createdDate, | ||
}); | ||
}; | ||
|
||
DevelopmentFundGrants.getWDFClaimStatus = async function (establishmentId) { | ||
return await this.findOne({ | ||
attributes: ['AgreementID', 'SignStatus'], | ||
where: { | ||
EstablishmentID: establishmentId, | ||
}, | ||
}); | ||
}; | ||
|
||
DevelopmentFundGrants.updateStatus = async function (establishmentId, status) { | ||
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. Similar blocks of code found in 2 locations. Consider refactoring. |
||
return await this.update( | ||
{ | ||
SignStatus: status, | ||
}, | ||
{ | ||
where: { | ||
EstablishmentID: establishmentId, | ||
}, | ||
}, | ||
); | ||
}; | ||
|
||
return DevelopmentFundGrants; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const express = require('express'); | ||
const router = express.Router({ mergeParams: true }); | ||
const models = require('../../../models'); | ||
const { createAgreement, queryAgreementStatus } = require('../../../utils/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: agreementId } = await createAgreement({ | ||
name, | ||
email, | ||
organisation: NameValue, | ||
address: address1, | ||
town, | ||
county, | ||
postcode, | ||
isNationalOrg: IsNationalOrg, | ||
}); | ||
// save to DB | ||
await models.DevelopmentFundGrants.saveWDFData({ | ||
agreementId, | ||
establishmentId, | ||
email, | ||
name, | ||
signStatus: data.status, | ||
createdDate: data.createdDate, | ||
}); | ||
|
||
return res.status(201).json({ agreementId }); | ||
} catch (err) { | ||
return next(Error('unable to create agreement')); | ||
} | ||
}; | ||
|
||
const getDevelopmentFundGrantStatus = async (req, res, next) => { | ||
try { | ||
// get signStatus | ||
const getWDFClaimStatus = await models.DevelopmentFundGrants.getWDFClaimStatus(req.body.establishmentId); | ||
const data = await queryAgreementStatus(getWDFClaimStatus.AgreementID); | ||
|
||
const signedStatus = getWDFClaimStatus.signStatus; | ||
const echoSignStatus = data.status; | ||
const returnStatus = signedStatus == 'SIGNED' ? signedStatus : echoSignStatus; | ||
|
||
if (signedStatus != 'SIGNED') { | ||
// update status to DB | ||
if (signedStatus != echoSignStatus) { | ||
await models.DevelopmentFundGrants.updateStatus(req.body.establishmentId, echoSignStatus); | ||
} | ||
} | ||
return res.status(200).json({ Status: returnStatus }); | ||
} catch (err) { | ||
console.error(err); | ||
return next(Error('unable to get the status')); | ||
} | ||
}; | ||
|
||
router.route('/').get(getDevelopmentFundGrantStatus); | ||
router.route('/').post(generateDevelopmentFundGrantLetter); | ||
|
||
module.exports = router; | ||
module.exports.generateDevelopmentFundGrantLetter = generateDevelopmentFundGrantLetter; | ||
module.exports.getDevelopmentFundGrantStatus = getDevelopmentFundGrantStatus; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
const router = require('express').Router(); | ||
const { hasPermission } = require('../../../utils/security/hasPermission'); | ||
const { | ||
generateDevelopmentFundGrantLetter, | ||
getDevelopmentFundGrantStatus, | ||
} = require('./generateDevelopmentFundGrantLetter'); | ||
|
||
const updateBUDataChanges = async (res) => { | ||
try { | ||
res.status(200).send(); | ||
} catch (error) { | ||
console.log(error); | ||
res.status(500).send(); | ||
} | ||
}; | ||
|
||
router.route('/').post(hasPermission('canManageWdfClaims'), updateBUDataChanges); | ||
router.route('/').post(generateDevelopmentFundGrantLetter); | ||
router.route('/').get(getDevelopmentFundGrantStatus); | ||
|
||
module.exports = router; | ||
module.exports.updateBUDataChanges = updateBUDataChanges; | ||
module.exports.generateDevelopmentFundGrantLetter = generateDevelopmentFundGrantLetter; | ||
module.exports.getDevelopmentFundGrantStatus = getDevelopmentFundGrantStatus; |
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.