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.
54 lines (53 loc) • 2.81 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const models_1 = require("../models");
const Client_1 = __importDefault(require("./Client"));
class CategoriesClient extends Client_1.default {
constructor() {
super(...arguments);
this._path = '/open-finances/categories';
}
getList(userId, isUserCategory) {
let params = '';
if (isUserCategory !== undefined && isUserCategory !== null)
params += `&isUserCategory=${isUserCategory}`;
return this.apiCore.doGet(`${this._path}?userId=${userId}${params}`, (response) => {
return response.data.map((category) => new models_1.Category(Object.assign(Object.assign({}, category), { imagePath: this.assetsUrl + category.imagePath })));
});
}
getListWithSubcategories(userId, isUserCategory) {
let params = '';
if (isUserCategory !== undefined && isUserCategory !== null)
params += `&isUserCategory=${isUserCategory}`;
return this.apiCore.doGet(`${this._path}?userId=${userId}${params}`, (response) => {
let categories = [];
if (response.data) {
categories = response.data
.filter((cat) => !cat.parentCategoryId)
.map((cat) => new models_1.ParentCategory(Object.assign(Object.assign({}, cat), { imagePath: this.assetsUrl + cat.imagePath })));
categories.forEach((parcat) => {
parcat.subcategories = response.data
.filter((rescat) => rescat.parentCategoryId === parcat.id)
.map((cat) => new models_1.Category(Object.assign(Object.assign({}, cat), { imagePath: this.assetsUrl + cat.imagePath })));
});
}
return categories;
});
}
get(id) {
return this.apiCore.doGet(`${this._path}/${id}`, (response) => new models_1.Category(Object.assign(Object.assign({}, response), { imagePath: this.assetsUrl + response.imagePath })));
}
create(categoryToCreate) {
return this.apiCore.doPost(this._path, categoryToCreate.toObject(), (response) => new models_1.Category(Object.assign(Object.assign({}, response), { imagePath: this.assetsUrl + response.imagePath })));
}
edit(id, categoryToUpdate) {
return this.apiCore.doPut(`${this._path}/${id}`, categoryToUpdate, (response) => new models_1.Category(Object.assign(Object.assign({}, response), { imagePath: this.assetsUrl + response.imagePath })));
}
delete(id) {
return this.apiCore.doDelete(`${this._path}/${id}`);
}
}
exports.default = CategoriesClient;