Skip to content
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
94 changes: 42 additions & 52 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
"@mojaloop/central-ledger": "8.2.4",
"@mojaloop/central-services-auth": "5.2.1",
"@mojaloop/central-services-database": "8.2.1",
"@mojaloop/central-services-error-handling": "8.6.2",
"@mojaloop/central-services-error-handling": "8.7.0",
"@mojaloop/central-services-health": "8.3.0",
"@mojaloop/central-services-logger": "8.6.0",
"@mojaloop/central-services-shared": "8.8.0",
"@mojaloop/central-services-shared": "8.8.1",
"@mojaloop/central-services-stream": "8.7.2",
"@mojaloop/forensic-logging-client": "8.3.0",
"@mojaloop/ml-number": "8.2.0",
Expand All @@ -55,7 +55,7 @@
"bluebird": "3.7.2",
"eslint": "6.8.0",
"faucet": "0.0.1",
"get-port": "5.1.0",
"get-port": "5.1.1",
"node-fetch": "2.6.0",
"nodemon": "2.0.2",
"npm-audit-resolver": "2.1.0",
Expand Down
32 changes: 28 additions & 4 deletions src/domain/settlement/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@
const arrayDiff = require('lodash').difference
const SettlementModel = require('../../models/settlement')
const SettlementModelModel = require('../../models/settlement/settlementModel')
const SettlementWindowContentModel = require('../../models/settlementWindowContent')
const SettlementWindowModel = require('../../models/settlementWindow')
const ErrorHandler = require('@mojaloop/central-services-error-handling')

const prepareParticipantsResult = function (participantCurrenciesList) {
const prepareParticipantsResult = (participantCurrenciesList) => {
const participantAccounts = {}
for (const account of participantCurrenciesList) {
const { id } = account
Expand Down Expand Up @@ -69,6 +70,20 @@ const prepareParticipantsResult = function (participantCurrenciesList) {
return Array.from(Object.keys(participantAccounts).map(participantId => participantAccounts[participantId]))
}

const groupSettlementWindowContentBySettlementWindow = (records) => {
const settlementWindows = {}
for (const record of records) {
const id = record.settlementWindowId
delete record.settlementWindowId
if (id in settlementWindows) {
settlementWindows[id].push(record)
} else {
settlementWindows[id] = record
}
}
return settlementWindows
}

module.exports = {
getById: async function ({ settlementId }, enums) {
const settlement = await SettlementModel.getById({ settlementId }, enums)
Expand Down Expand Up @@ -193,19 +208,28 @@ module.exports = {
throw ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.VALIDATION_ERROR, `Inapplicable windows ${nonApplicableIdList.join(', ')}`)
}

// follow-up next
const settlementId = await SettlementModel.triggerEvent({ idList, reason }, enums)
// settlement event trigger
const settlementId = await SettlementModel.triggerSettlementEvent({ idList, reason }, settlementModelData, enums)

// retrieve resulting data for response
const settlement = await SettlementModel.getById({ settlementId })
const settlementWindowsList = await SettlementWindowModel.getBySettlementId({ settlementId })
const settlementWindowContentAll = await SettlementWindowContentModel.getBySettlementId(settlementId)
const settlementWindowsContent = groupSettlementWindowContentBySettlementWindow(settlementWindowContentAll)
const settlementWindowsWithContent = settlementWindowsList.map(record => {
record.content = settlementWindowsContent[record.id]
return record
})
const participantCurrenciesList = await SettlementModel.settlementParticipantCurrency.getParticipantCurrencyBySettlementId({ settlementId })
const participants = prepareParticipantsResult(participantCurrenciesList)
return {
id: settlement.settlementId,
settlementModel,
state: settlement.state,
reason: settlement.reason,
createdDate: settlement.createdDate,
changedDate: settlement.changedDate,
settlementWindows: settlementWindowsList,
settlementWindows: settlementWindowsWithContent,
participants
}
},
Expand Down
38 changes: 37 additions & 1 deletion src/interface/swagger.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"swagger": "2.0",
"info": {
"version": "1.9.0",
"version": "1.9.1",
"title": "MOJALOOP Central Settlements",
"description": "Mojaloop API for Settlements."
},
Expand Down Expand Up @@ -1105,13 +1105,49 @@
"createdDate": {
"type": "string"
},
"changedDate": {
"type": "string"
},
"content": {
"type": "array",
"items": {
"$ref": "#/definitions/SettlementWindowContent"
}
}
},
"required": [
"id",
"state",
"createdDate"
]
},
"SettlementWindowContent": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"state": {
"type": "string"
},
"ledgerAccountType": {
"type": "string"
},
"currencyId": {
"type": "string"
},
"createdDate": {
"type": "string"
},
"changedDate": {
"type": "string"
}
},
"required": [
"id",
"state",
"ledgerAccountType",
"currencyId",
"createdDate"
]
},
Expand Down
Loading