open-banking-pfm-sdk
Version:
The Open Banking PFM SDK uses Client classes and with **Promises** to get responses from the Open Banking PFM API in an easier way and structured as data models.
45 lines (44 loc) • 2.04 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Account_1 = __importDefault(require("../models/Account"));
const Client_1 = __importDefault(require("./Client"));
class AccountsClient extends Client_1.default {
constructor() {
super(...arguments);
this._path = '/open-finances/accounts';
}
processListResponse(response) {
return response.data.map((accountData) => new Account_1.default(accountData));
}
processResponse(response) {
if (!response) {
return null;
}
return new Account_1.default(response);
}
getList(userId, accountParams) {
let params = `?userId=${userId}`;
if ((accountParams === null || accountParams === void 0 ? void 0 : accountParams.isBankAggregation) !== undefined &&
(accountParams === null || accountParams === void 0 ? void 0 : accountParams.isBankAggregation) !== null)
params += `&isBankAggregation=${accountParams.isBankAggregation ? 'true' : 'false'}`;
if ((accountParams === null || accountParams === void 0 ? void 0 : accountParams.cursor) !== undefined && (accountParams === null || accountParams === void 0 ? void 0 : accountParams.cursor) !== null)
params += `&cursor=${accountParams.cursor}`;
return this.apiCore.doGet(`${this._path}${params}`, this.processListResponse);
}
get(id) {
return this.apiCore.doGet(`${this._path}/${id}`, this.processResponse);
}
create(accountToCreate) {
return this.apiCore.doPost(this._path, accountToCreate.toObject(), this.processResponse);
}
edit(id, accountToUpdate) {
return this.apiCore.doPut(`${this._path}/${id}`, accountToUpdate.toObject(), this.processResponse);
}
delete(id) {
return this.apiCore.doDelete(`${this._path}/${id}`);
}
}
exports.default = AccountsClient;