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

added new message to notification topic for limit adjustment. #236

Merged
merged 6 commits into from
Jan 24, 2019
Merged
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
35 changes: 32 additions & 3 deletions src/domain/participant/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ const getLimitsForAllParticipants = async ({ currency = null, type = null }) =>
* "currency": "USD",
* "limit": {
* "type": "NET_DEBIT_CAP",
* "value": 10000000
* "value": 10000000,
* "thresholdAlarmPercentage": 10
* }
* }
*
Expand All @@ -449,14 +450,42 @@ const getLimitsForAllParticipants = async ({ currency = null, type = null }) =>

const adjustLimits = async (name, payload) => {
try {
const participant = await ParticipantFacade.getByNameAndCurrency(name, payload.currency, Enum.LedgerAccountType.POSITION)
let { limit, currency } = payload
const participant = await ParticipantFacade.getByNameAndCurrency(name, currency, Enum.LedgerAccountType.POSITION)
participantExists(participant)
return ParticipantFacade.adjustLimits(participant.participantCurrencyId, payload.limit)
let result = await ParticipantFacade.adjustLimits(participant.participantCurrencyId, limit)
payload.name = name
await Utility.produceGeneralMessage(TransferEventType.NOTIFICATION, TransferEventAction.EVENT, createLimitAdjustmentMessageProtocol(payload), Utility.ENUMS.STATE.SUCCESS)
return result
} catch (err) {
throw err
}
}

const createLimitAdjustmentMessageProtocol = (payload, action = 'limitAdjustment', state = '', pp = '') => {
return {
id: Uuid(),
from: payload.name,
to: 'SYSTEM',
type: 'application/json',
content: {
header: {},
payload
},
metadata: {
event: {
id: Uuid(),
responseTo: '',
type: 'notification',
action,
createdAt: new Date(),
state
}
},
pp
}
}

/**
* @function GetPositions
*
Expand Down