This repository has been archived by the owner on Feb 7, 2025. It is now read-only.
generated from DEFRA/ffc-template-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Sfi 2199 subscribe to submitted payment requests #4
Merged
marctemp
merged 72 commits into
main
from
SFI-2199-subscribe-to-submitted-payment-requests
Aug 18, 2022
Merged
Changes from all commits
Commits
Show all changes
72 commits
Select commit
Hold shift + click to select a range
f8445f6
bumpin version
marctemp 5945a9a
added organisations db tbl
marctemp 02753e1
SFI-2199 Subscribe to submitted payment requests
AbidemiAdio 33075f1
basic db schemas added
marctemp d963235
adding explicit nullable fks
marctemp ae7f04b
Added Data Model
AbidemiAdio 9f4eba8
pk-fk setup
marctemp c6e9f05
added snyk ignores
marctemp 2cbce74
agreementNumber in claim is same as PR, therefore droped in claim table
marctemp 0d543c0
duplicate invoiceNumber, dropped from claims
marctemp 78efaa8
reference is varchar(9), removing comment
marctemp 2f95ca4
schemes renamed to fundings
marctemp 4c7b075
referenceId and correlationId using same UUID datatype
marctemp 2745534
adjusting decimal for areaclaimed to match BPS
marctemp 005c851
adding scheme table
marctemp c55bf36
split address into distinct gov uk appoved parts
marctemp bef23a3
added invoiceNumber table
marctemp 7b72ddb
added addressLine3 to org
marctemp 7a5f247
letting John have this one
marctemp c5406ca
Merge branch 'main' into SFI-2199-subscribe-to-submitted-payment-requ…
marctemp b87df37
moved sequilze object outside function scope
marctemp 85d6a22
missed db issues
marctemp f2fe3cb
bumpin version
marctemp f02d83f
saving progress
marctemp c9aa039
fixing typo issues
marctemp feec69d
bumpin version
marctemp 152c52b
Merge branch 'main' into pay-2195-add-constructor-db
marctemp e7adf42
bumpin version
marctemp fd4db12
renaming claims to calculations
marctemp 51fa0db
funding to calculations now many to many
marctemp 8373381
Merge branch 'pay-2195-add-constructor-db' into SFI-2199-subscribe-to…
marctemp 8700d3e
fixing typo
marctemp 09388cd
Merge branch 'pay-2195-add-constructor-db' into SFI-2199-subscribe-to…
marctemp 19f4e5b
simple savedown successful
marctemp 79491e6
wip
marctemp da5ec85
Merge branch 'main' into SFI-2199-subscribe-to-submitted-payment-requ…
marctemp 7cbeb21
renaming process pr to process submit pr
marctemp 140f420
bumpin
marctemp d40813b
modified areaClaimed to match data
marctemp ee60119
tests added
marctemp 447008e
added throwing processPaymentRequest test case
marctemp 283e89b
bumpin version
marctemp 6ed9497
Merge branch 'main' into SFI-2199-subscribe-to-submitted-payment-requ…
marctemp 216d401
added placeholder reverseEngineerInvoiceNumber func tests
marctemp 764abc6
fixing changelog typo
marctemp a16d4b5
fixed standard isssues
marctemp 8d4fdde
removed unness deletion of obj key
marctemp 41c92d6
reverse obj expansion ovverride
marctemp 3559e18
hidious camel naming replaced with kebab
marctemp 066b7da
hidious camel naming replaced with kebab
marctemp de9f2f8
adding constants and mock constants
marctemp d1e867f
fixing wrong reverse eng in test descriptions
marctemp 0d5fbdf
resetMock debate resolved
marctemp 101e2d2
fixed internal erro throwing test issue, added for all
marctemp fd3eac2
added check tht msg not marked as complete if fails to process
marctemp 88b29a6
using sequilize create returning newly created obj
marctemp e826c2e
added received to allow logic to find most recent of "same" prs
marctemp df77fa5
renaming schedules to match tech debt names
marctemp 34b1e05
using ref Id rather than invoice number to look for duplicates
marctemp c8caaee
changes made
marctemp 5118483
added async for processing pr
marctemp abeaec9
save returning explicit
marctemp 691a31b
forgotten import name change
marctemp f51d662
added schemes id and name
marctemp ca5eee8
adding scheme id and scheme code enums to async
marctemp 9e69e1c
mising closing changeset tag
marctemp c543d54
adding int tests
marctemp e6fb470
added constants used in mocks
marctemp 1b4233e
adding int tests to ensure all scheme ids are accepted
marctemp 3769200
removing db saved records before int tests
marctemp ba8fbb7
using status in dup check
marctemp 4ebf1c9
adding missing schemeId to paymentRequests model
marctemp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
SFI_GROSS_VALUE_AP: 'SOS273' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
GBP: 'GBP' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
RP00: 'RP00' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
GROSS_VALUE: 'G00 - Gross value of claim' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
DRD10: 'DRD10' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
ARABLE_SOIL_INTRODUCTORY: 'Arable and horticultural soils: Introductory' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
ARABLE_SOIL_INTRODUCTORY: '80001' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { ARABLE_SOIL_INTRODUCTORY: ARABLE_SOIL_INTRODUCTORY_CODE } = require('./funding-codes') | ||
const { ARABLE_SOIL_INTRODUCTORY } = require('./funding-code-names') | ||
|
||
module.exports = [{ | ||
fundingCode: ARABLE_SOIL_INTRODUCTORY_CODE, | ||
name: ARABLE_SOIL_INTRODUCTORY | ||
}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
AP: 'AP', | ||
AR: 'AR' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
FIRST_PAYMENT: 1, | ||
POST_PAYMENT_ADJUSTMENT: 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
QUARTERLY: 'Q4', | ||
MONTHLY: 'M12', | ||
THREE_DAY_QUARTERLY: 'T4' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
SFI: 1, | ||
SFI_PILOT: 2, | ||
LUMP_SUMS: 3, | ||
LNR: 4, | ||
VET_VISITS: 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
LNR: 'LNR', | ||
LUMP_SUMS: 'Lump Sums', | ||
SFI: 'SFI', | ||
SFI_PILOT: 'SFIP', | ||
VET_VISITS: 'Vet Visits' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const { | ||
LNR: LNR_ID, | ||
LUMP_SUMS: LUMP_SUMS_ID, | ||
SFI: SFI_ID, | ||
SFI_PILOT: SFI_PILOT_ID, | ||
VET_VISITS: VET_VISITS_ID | ||
} = require('./scheme-ids') | ||
|
||
const { | ||
LNR, | ||
LUMP_SUMS, | ||
SFI, | ||
SFI_PILOT, | ||
VET_VISITS | ||
} = require('./scheme-names') | ||
|
||
module.exports = [{ | ||
schemeId: LNR_ID, | ||
name: LNR | ||
}, | ||
{ | ||
schemeId: LUMP_SUMS_ID, | ||
name: LUMP_SUMS | ||
}, | ||
{ | ||
schemeId: SFI_ID, | ||
name: SFI | ||
}, | ||
{ | ||
schemeId: SFI_PILOT_ID, | ||
name: SFI_PILOT | ||
}, | ||
{ | ||
schemeId: VET_VISITS_ID, | ||
name: VET_VISITS | ||
}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
SFI: 'SFI' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
IN_PROGRESS: 'In progress', | ||
COMPLETED: 'Completed' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
app/inbound/get-completed-payment-request-by-reference-id.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const db = require('../data') | ||
const { COMPLETED } = require('../constants/statuses') | ||
|
||
const getCompletedPaymentRequestByReferenceId = async (referenceId, transaction) => { | ||
return db.paymentRequest.findOne({ | ||
transaction, | ||
lock: true, | ||
where: { | ||
referenceId, | ||
status: COMPLETED | ||
} | ||
}) | ||
} | ||
|
||
module.exports = getCompletedPaymentRequestByReferenceId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const processSubmitPaymentRequest = require('./process-submit-payment-request') | ||
|
||
module.exports = processSubmitPaymentRequest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const db = require('../data') | ||
|
||
const { COMPLETED } = require('../constants/statuses') | ||
const getCompletedPaymentRequestByReferenceId = require('./get-completed-payment-request-by-reference-id') | ||
const saveInvoiceNumber = require('./save-invoice-number') | ||
const savePaymentRequest = require('./save-payment-request') | ||
const saveInvoiceLines = require('./save-invoice-lines') | ||
|
||
const processSubmitPaymentRequest = async (paymentRequest) => { | ||
const transaction = await db.sequelize.transaction() | ||
try { | ||
const existingPaymentRequest = await getCompletedPaymentRequestByReferenceId(paymentRequest.referenceId, transaction) | ||
|
||
if (existingPaymentRequest) { | ||
marctemp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
console.info(`Duplicate payment request received, skipping ${existingPaymentRequest.referenceId}`) | ||
await transaction.rollback() | ||
} else { | ||
await saveInvoiceNumber(paymentRequest.invoiceNumber, transaction) | ||
const savedPaymentRequest = await savePaymentRequest({ ...paymentRequest, status: COMPLETED }, transaction) | ||
await saveInvoiceLines(paymentRequest.invoiceLines, savedPaymentRequest.paymentRequestId, transaction) | ||
await transaction.commit() | ||
} | ||
} catch (error) { | ||
await transaction.rollback() | ||
throw (error) | ||
} | ||
} | ||
|
||
module.exports = processSubmitPaymentRequest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const db = require('../data') | ||
|
||
const saveInvoiceLines = async (invoiceLines, paymentRequestId, transaction) => { | ||
for (const invoiceLine of invoiceLines) { | ||
delete invoiceLine.invoiceLineId | ||
invoiceLine.fundingCode = invoiceLine.schemeCode | ||
await db.invoiceLine.create({ ...invoiceLine, paymentRequestId }, { transaction }) | ||
} | ||
} | ||
|
||
module.exports = saveInvoiceLines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const db = require('../data') | ||
const reverseEngineerInvoiceNumber = require('../processing/reverse-engineer-invoice-number') | ||
|
||
const saveInvoiceNumber = async (invoiceNumber, transaction) => { | ||
await db.invoiceNumber.create({ | ||
invoiceNumber, | ||
originalInvoiceNumber: reverseEngineerInvoiceNumber(invoiceNumber) | ||
}, | ||
{ transaction } | ||
) | ||
} | ||
|
||
module.exports = saveInvoiceNumber |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const db = require('../data') | ||
|
||
const savePaymentRequest = async (paymentRequest, transaction) => { | ||
delete paymentRequest.paymentRequestId | ||
return db.paymentRequest.create({ ...paymentRequest, received: new Date() }, { transaction }) | ||
} | ||
|
||
module.exports = savePaymentRequest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const reverseEngineerInvoiceNumber = (invoiceNumber) => { | ||
return `original${invoiceNumber.slice(0, 5)}` | ||
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. I know this is just a placeholder so this isn't a suggestion for change, more just a snippet of wisdom. Because we're subscribing to all submitted payments, we're going to pass Vets, Lump Sums, Pilot and SFI through this. All the Siti Agri ones we'll be able to reverse engineer back to the SITI invoice to match to DWH but with slightly different values for what you have as |
||
} | ||
|
||
module.exports = reverseEngineerInvoiceNumber |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?xml version="1.1" encoding="UTF-8" standalone="no"?> | ||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-3.9.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.9.xsd"> | ||
<changeSet author="Marc Templeton" id="1"> | ||
<tagDatabase tag="v1.1.0" /> | ||
</changeSet> | ||
<changeSet author="Marc Templeton" id="2"> | ||
<modifyDataType tableName="fundings" columnName="areaClaimed" newDataType="DECIMAL(11,4)" /> | ||
<rollback> | ||
<modifyDataType tableName="fundings" columnName="areaClaimed" newDataType="DECIMAL(19,4)" /> | ||
</rollback> | ||
</changeSet> | ||
<changeSet author="Marc Templeton" id="3"> | ||
<insert tableName="schemes"> | ||
<column name="schemeId" value="1" /> | ||
<column name="name" value="SFI" /> | ||
</insert> | ||
</changeSet> | ||
<changeSet author="Marc Templeton" id="4"> | ||
<insert tableName="schemes"> | ||
<column name="schemeId" value="2" /> | ||
<column name="name" value="SFI Pilot" /> | ||
</insert> | ||
</changeSet> | ||
<changeSet author="Marc Templeton" id="5"> | ||
<insert tableName="schemes"> | ||
<column name="schemeId" value="3" /> | ||
<column name="name" value="Lump Sums" /> | ||
</insert> | ||
</changeSet> | ||
<changeSet author="Marc Templeton" id="6"> | ||
<insert tableName="schemes"> | ||
<column name="schemeId" value="4" /> | ||
<column name="name" value="LNR" /> | ||
</insert> | ||
</changeSet> | ||
<changeSet author="Marc Templeton" id="7"> | ||
<insert tableName="schemes"> | ||
<column name="schemeId" value="5" /> | ||
<column name="name" value="Vet Visits" /> | ||
</insert> | ||
</changeSet> | ||
<changeSet author="Marc Templeton" id="8"> | ||
<modifyDataType tableName="fundingOptions" columnName="name" newDataType="VARCHAR(60)" /> | ||
<rollback> | ||
<modifyDataType tableName="fundingOptions" columnName="name" newDataType="VARCHAR(30)" /> | ||
</rollback> | ||
</changeSet> | ||
<changeSet author="Marc Templeton" id="9"> | ||
<insert tableName="fundingOptions"> | ||
<column name="fundingCode" value="80001" /> | ||
<column name="name" value="Arable and horticultural soils: Introductory" /> | ||
</insert> | ||
</changeSet> | ||
<changeSet author="Marc Templeton" id="10"> | ||
<addColumn tableName="paymentRequests"> | ||
<column afterColumn="marketingYear" name="received" type="TIMESTAMP" /> | ||
<column afterColumn="schedule" name="status" type="VARCHAR(20)" /> | ||
</addColumn> | ||
</changeSet> | ||
<changeSet author="Marc Templeton" id="11"> | ||
<dropColumn tableName="paymentRequests"> | ||
<column name="sitiAgriInvoiceNumber" /> | ||
</dropColumn> | ||
</changeSet> | ||
</databaseChangeLog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Probably fine for now but may be a limitation if we have tests that cover three payment requests as
3
is still a post payment adjustment.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.
yup, recognised this myself