monzolib
Version:
Fully Featured JS/Node Monzo Library
91 lines (90 loc) • 2.07 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const date_fns_1 = require("date-fns");
const Amount_1 = require("./Amount");
class Pot {
constructor(pot) {
this.pot = pot;
}
get balance() {
return new Amount_1.Amount({
domestic: { amount: this.pot.balance, currency: 'GBP' },
});
}
get created() {
return date_fns_1.parseISO(this.pot.created);
}
get currency() {
return this.pot.currency;
}
get deleted() {
return this.pot.deleted;
}
get id() {
return this.pot.id;
}
get goalAmount() {
return this.pot.goal_amount
? new Amount_1.Amount({
domestic: { amount: this.pot.goal_amount, currency: 'GBP' },
})
: undefined;
}
get maximumBalance() {
return this.pot.maximum_balance;
}
get minimumBalance() {
return this.pot.minimum_balance;
}
get name() {
return this.pot.name;
}
get roundUp() {
return this.pot.round_up;
}
get style() {
return this.pot.style;
}
get type() {
return this.pot.type;
}
get updated() {
return date_fns_1.parseISO(this.pot.updated);
}
deletePotRequest() {
return {
path: `/pots/${this.id}`,
method: 'DELETE',
};
}
depositRequest(depositOpts) {
return {
path: `/pots/${this.id}/deposit`,
method: 'PUT',
body: depositOpts,
};
}
withdrawRequest(withdrawOpts) {
return {
path: `/pots/${this.id}/withdraw`,
method: 'PUT',
body: withdrawOpts,
};
}
toString() {
return `${this.pot.name} (${this.pot.id})`;
}
}
exports.Pot = Pot;
function potsRequest() {
return {
path: '/pots',
};
}
exports.potsRequest = potsRequest;
function potRequest(id) {
return {
path: `/pots/${id}`,
};
}
exports.potRequest = potRequest;