From 29bd1d1460ce8e6fa1adb919abd6d2a880c52846 Mon Sep 17 00:00:00 2001 From: Peter Smart Date: Tue, 30 Mar 2021 10:49:05 +0100 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20unwrap=20api=20respo?= =?UTF-8?q?nse=20result=20for=20easier=20access?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGE: 🧨 disbursements isPayerActive now returns simple boolean --- examples/disbursements.js | 6 +++--- src/disbursements.ts | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/disbursements.js b/examples/disbursements.js index e14516f..d787766 100644 --- a/examples/disbursements.js +++ b/examples/disbursements.js @@ -14,9 +14,9 @@ const partyIdType = momo.PayerType.MSISDN; // Transfer disbursements .isPayerActive(partyId, partyIdType) - .then((data) => { - console.log(data); - if (!data || !data.result || data.result !== true) { + .then((isActive) => { + console.log("Is Active ? ", isActive); + if (!isActive) { return Promise.reject("Party not active"); } return disbursements.transfer({ diff --git a/src/disbursements.ts b/src/disbursements.ts index 5ff4640..66fb5a2 100644 --- a/src/disbursements.ts +++ b/src/disbursements.ts @@ -175,9 +175,10 @@ export default class Disbursements { public isPayerActive( id: string, type: PartyIdType = PartyIdType.MSISDN - ): Promise<{ result: boolean }> { + ): Promise { return this.client .get<{ result: boolean }>(`/disbursement/v1_0/accountholder/${String(type).toLowerCase()}/${id}/active`) - .then(response => response.data); + .then(response => response.data) + .then(data => data.result ? data.result : false) } }