Skip to content

Commit

Permalink
refactor: 💡 unwrap api response result for easier access
Browse files Browse the repository at this point in the history
BREAKING CHANGE: 🧨 disbursements isPayerActive now returns simple boolean
  • Loading branch information
iyiolapeter authored and ernest-okot committed Mar 31, 2021
1 parent 3b74e6e commit 29bd1d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions examples/disbursements.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
5 changes: 3 additions & 2 deletions src/disbursements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ export default class Disbursements {
public isPayerActive(
id: string,
type: PartyIdType = PartyIdType.MSISDN
): Promise<{ result: boolean }> {
): Promise<boolean> {
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)
}
}

0 comments on commit 29bd1d1

Please sign in to comment.