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

Map SBI to FRN #11

Merged
merged 4 commits into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 14 additions & 0 deletions app/payment-request-mapping/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ async function savePaymentRequest (paymentRequest) {
paymentRequest.invoiceNumber = generateInvoiceNumber(paymentRequest)
paymentRequest.schemeId = await getSchemeId(paymentRequest.sourceSystem, transaction)
paymentRequest.ledger = paymentRequest.ledger ? paymentRequest.ledger : 'AP'

if (!paymentRequest.frn) {
paymentRequest.frn = await getFrn(paymentRequest.sbi, transaction)
}

const savedPaymentRequest = await db.paymentRequest.create(paymentRequest, { transaction })
await processInvoiceLines(paymentRequest.invoiceLines, savedPaymentRequest.paymentRequestId, transaction)
await db.schedule.create({ schemeId: paymentRequest.schemeId, paymentRequestId: savedPaymentRequest.paymentRequestId, planned: new Date() }, { transaction })
Expand Down Expand Up @@ -55,6 +60,15 @@ async function getSchemeCode (standardCode, transaction) {
return schemeCode.schemeCode
}

async function getFrn (sbi, transaction) {
const frn = await db.frn.findOne({ where: { sbi: sbi } }, { transaction })
if (frn) {
return Number(frn.frn)
}

throw new Error('No FRN found in db table frn using SBI look up !')
}

module.exports = {
savePaymentRequest
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ffc-sfi-payments",
"version": "1.6.0",
"version": "1.7.0",
"description": "FFC SFI payment services",
"homepage": "https://github.com/DEFRA/ffc-sfi-payments",
"main": "app/index.js",
Expand Down