UNPKG

@mojaloop/central-services-shared

Version:
87 lines (75 loc) 3.4 kB
/***** License -------------- Copyright © 2020-2025 Mojaloop Foundation The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Contributors -------------- This is the official list of the Mojaloop project contributors for this file. Names of the original copyright holders (individuals or organizations) should be listed with a '*' in the first column. People who have contributed from an organization can be listed under the organization that actually holds the copyright for their contributions (see the Mojaloop Foundation for an example). Those individuals should have their names indented and be marked with a '-'. Email address can be added optionally within square brackets <email>. * Mojaloop Foundation - Name Surname <name.surname@mojaloop.io> * ModusBox - Georgi Georgiev <georgi.georgiev@modusbox.com> -------------- ******/ 'use strict' const SettlementEnum = require('../../src/enums/settlements') const transpose = require('../../src/util/helpers').transpose const validateSettlementModel = (delay, granularity, interchange) => { const reasons = [] let isValid = true let settlementDelay let settlementGranularity let settlementInterchange const SettlementDelayTransposed = transpose(SettlementEnum.SettlementDelay) const SettlementGranularityTransposed = transpose(SettlementEnum.SettlementGranularity) const SettlementInterchangeTransposed = transpose(SettlementEnum.SettlementInterchange) if (SettlementEnum.SettlementDelay[delay]) { settlementDelay = delay } else if (SettlementDelayTransposed[delay]) { settlementDelay = SettlementDelayTransposed[delay] } else { reasons.push('Invalid settlement delay value') isValid = false } if (SettlementEnum.SettlementGranularity[granularity]) { settlementGranularity = granularity } else if (SettlementGranularityTransposed[granularity]) { settlementGranularity = SettlementGranularityTransposed[granularity] } else { reasons.push('Invalid settlement granularity value') isValid = false } if (SettlementEnum.SettlementInterchange[interchange]) { settlementInterchange = interchange } else if (SettlementInterchangeTransposed[interchange]) { settlementInterchange = SettlementInterchangeTransposed[interchange] } else { reasons.push('Invalid settlement interchange value') isValid = false } if (isValid) { const found = SettlementEnum.ValidSettlementModels.find(model => { return settlementDelay === model.settlementDelay && settlementGranularity === model.settlementGranularity && settlementInterchange === model.settlementInterchange }) if (!found) { reasons.push('Invalid settlement model definition - delay-granularity-interchange combination is not supported') isValid = false } } return { isValid, reasons } } module.exports = { validateSettlementModel }