Skip to content

Commit 6f24564

Browse files
authored
added new message to notification topic for limit adjustment. (#236)
* added new message to notification topic for limit adjustment. tests still pending * jsdocs update and making code more readable
1 parent 3a7b47f commit 6f24564

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

‎src/domain/participant/index.js‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,8 @@ const getLimitsForAllParticipants = async ({ currency = null, type = null }) =>
440440
* "currency": "USD",
441441
* "limit": {
442442
* "type": "NET_DEBIT_CAP",
443-
* "value": 10000000
443+
* "value": 10000000,
444+
* "thresholdAlarmPercentage": 10
444445
* }
445446
* }
446447
*
@@ -449,14 +450,42 @@ const getLimitsForAllParticipants = async ({ currency = null, type = null }) =>
449450

450451
const adjustLimits = async (name, payload) => {
451452
try {
452-
const participant = await ParticipantFacade.getByNameAndCurrency(name, payload.currency, Enum.LedgerAccountType.POSITION)
453+
let { limit, currency } = payload
454+
const participant = await ParticipantFacade.getByNameAndCurrency(name, currency, Enum.LedgerAccountType.POSITION)
453455
participantExists(participant)
454-
return ParticipantFacade.adjustLimits(participant.participantCurrencyId, payload.limit)
456+
let result = await ParticipantFacade.adjustLimits(participant.participantCurrencyId, limit)
457+
payload.name = name
458+
await Utility.produceGeneralMessage(TransferEventType.NOTIFICATION, TransferEventAction.EVENT, createLimitAdjustmentMessageProtocol(payload), Utility.ENUMS.STATE.SUCCESS)
459+
return result
455460
} catch (err) {
456461
throw err
457462
}
458463
}
459464

465+
const createLimitAdjustmentMessageProtocol = (payload, action = 'limitAdjustment', state = '', pp = '') => {
466+
return {
467+
id: Uuid(),
468+
from: payload.name,
469+
to: 'SYSTEM',
470+
type: 'application/json',
471+
content: {
472+
header: {},
473+
payload
474+
},
475+
metadata: {
476+
event: {
477+
id: Uuid(),
478+
responseTo: '',
479+
type: 'notification',
480+
action,
481+
createdAt: new Date(),
482+
state
483+
}
484+
},
485+
pp
486+
}
487+
}
488+
460489
/**
461490
* @function GetPositions
462491
*

0 commit comments

Comments
 (0)