UNPKG

wallee

Version:
300 lines (299 loc) 13.5 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.InternalTransferBankTransactionService = void 0; const Promise = require("bluebird"); const axios = require("axios"); const HMACAuthentication_1 = require("../auth/HMACAuthentication"); const ObjectSerializer_1 = require("../serializers/ObjectSerializer"); const ClientError_1 = require("../models/ClientError"); const ServerError_1 = require("../models/ServerError"); class InternalTransferBankTransactionService { constructor(configuration) { this._basePath = 'https://app-wallee.com:443/api'; this._defaultHeaders = {}; this._useQuerystring = false; this._timeout = 25; this._defaultAuthentication = new HMACAuthentication_1.HMACAuthentication(configuration).apply; this._defaultHeaders = configuration.default_headers; this.setTimeout(configuration.timeout); } /** * Set timeout in seconds. Default timeout: 25 seconds * @param {number} timeout */ set timeout(timeout) { this.setTimeout(timeout); } setTimeout(timeout) { if (timeout !== undefined) { if (!Number.isInteger(timeout)) { throw new Error('Timeout value has to be integer'); } if (timeout) { this._timeout = timeout; } else { throw new Error('Timeout value has to be greater than 0'); } } } set basePath(basePath) { this._basePath = basePath; } get basePath() { return this._basePath; } setDefaultAuthentication(auth) { this._defaultAuthentication = auth; } getVersion() { if (typeof (process) !== 'undefined' && process && process.version) { return 'node ' + process.version; } else { return 'unknown'; } } /** * Counts the number of items in the database as restricted by the given filter. * @summary Count * @param spaceId * @param filter The filter which restricts the entities which are used to calculate the count. * @param {*} [options] Override http request options. */ count(spaceId, filter, options = {}) { const url = '/internal-transfer-bank-transaction/count'; let queryParams = {}; let headers = Object.assign({}, this._defaultHeaders); // verify required parameter 'spaceId' is not null or undefined if (spaceId === null || spaceId === undefined) { throw new Error('Required parameter spaceId was null or undefined when calling count.'); } if (spaceId !== undefined) { queryParams['spaceId'] = ObjectSerializer_1.ObjectSerializer.serialize(spaceId, "number"); } headers['Content-Type'] = 'application/json;charset=utf-8'; Object.assign(headers, options.headers); let defaultHeaders = { "x-meta-sdk-version": "4.7.0", "x-meta-sdk-language": "typescript", "x-meta-sdk-provider": "wallee", "x-meta-sdk-language-version": this.getVersion(), }; Object.assign(headers, defaultHeaders); let requestConfig = { url, method: 'POST', baseURL: this._basePath, headers, params: queryParams, data: filter, timeout: this._timeout * 1000, responseType: 'json', }; const axiosInstance = axios.default.create(); axiosInstance.interceptors.request.use(this._defaultAuthentication); return new Promise((resolve, reject) => { axiosInstance.request(requestConfig) .then(success => { let body; body = ObjectSerializer_1.ObjectSerializer.deserialize(success.data, "number"); return resolve({ response: success.request.res, body: body }); }, failure => { var _a, _b, _c, _d, _e; let errorObject; if ((_a = failure.response) === null || _a === void 0 ? void 0 : _a.status) { if (failure.response.status >= 400 && failure.response.status <= 499) { errorObject = new ClientError_1.ClientError(); } else if (failure.response.status >= 500 && failure.response.status <= 599) { errorObject = new ServerError_1.ServerError(); } else { errorObject = new Object(); } } else { errorObject = new Object(); } return reject({ errorType: errorObject.constructor.name, date: (new Date()).toDateString(), statusCode: ((_b = failure.response) === null || _b === void 0 ? void 0 : _b.status) && isNaN(failure.response.status) ? String(failure.response.status) : "Unknown", statusMessage: ((_c = failure.response) === null || _c === void 0 ? void 0 : _c.statusText) != null ? failure.response.statusText : "Unknown", body: (_d = failure.response) === null || _d === void 0 ? void 0 : _d.data, response: (_e = failure.response) === null || _e === void 0 ? void 0 : _e.request.res }); }) .catch(error => { return reject(error); }); }); } ; /** * Reads the entity with the given 'id' and returns it. * @summary Read * @param spaceId * @param id The ID of the internal transfer bank transaction which should be returned. * @param {*} [options] Override http request options. */ read(spaceId, id, options = {}) { const url = '/internal-transfer-bank-transaction/read'; let queryParams = {}; let headers = Object.assign({}, this._defaultHeaders); // verify required parameter 'spaceId' is not null or undefined if (spaceId === null || spaceId === undefined) { throw new Error('Required parameter spaceId was null or undefined when calling read.'); } // verify required parameter 'id' is not null or undefined if (id === null || id === undefined) { throw new Error('Required parameter id was null or undefined when calling read.'); } if (spaceId !== undefined) { queryParams['spaceId'] = ObjectSerializer_1.ObjectSerializer.serialize(spaceId, "number"); } if (id !== undefined) { queryParams['id'] = ObjectSerializer_1.ObjectSerializer.serialize(id, "number"); } headers['Content-Type'] = '*/*'; Object.assign(headers, options.headers); let defaultHeaders = { "x-meta-sdk-version": "4.7.0", "x-meta-sdk-language": "typescript", "x-meta-sdk-provider": "wallee", "x-meta-sdk-language-version": this.getVersion(), }; Object.assign(headers, defaultHeaders); let requestConfig = { url, method: 'GET', baseURL: this._basePath, headers, params: queryParams, timeout: this._timeout * 1000, responseType: 'json', }; const axiosInstance = axios.default.create(); axiosInstance.interceptors.request.use(this._defaultAuthentication); return new Promise((resolve, reject) => { axiosInstance.request(requestConfig) .then(success => { let body; body = ObjectSerializer_1.ObjectSerializer.deserialize(success.data, "InternalTransferBankTransaction"); return resolve({ response: success.request.res, body: body }); }, failure => { var _a, _b, _c, _d, _e; let errorObject; if ((_a = failure.response) === null || _a === void 0 ? void 0 : _a.status) { if (failure.response.status >= 400 && failure.response.status <= 499) { errorObject = new ClientError_1.ClientError(); } else if (failure.response.status >= 500 && failure.response.status <= 599) { errorObject = new ServerError_1.ServerError(); } else { errorObject = new Object(); } } else { errorObject = new Object(); } return reject({ errorType: errorObject.constructor.name, date: (new Date()).toDateString(), statusCode: ((_b = failure.response) === null || _b === void 0 ? void 0 : _b.status) && isNaN(failure.response.status) ? String(failure.response.status) : "Unknown", statusMessage: ((_c = failure.response) === null || _c === void 0 ? void 0 : _c.statusText) != null ? failure.response.statusText : "Unknown", body: (_d = failure.response) === null || _d === void 0 ? void 0 : _d.data, response: (_e = failure.response) === null || _e === void 0 ? void 0 : _e.request.res }); }) .catch(error => { return reject(error); }); }); } ; /** * Searches for the entities as specified by the given query. * @summary Search * @param spaceId * @param query The query restricts the internal transfer bank transactions which are returned by the search. * @param {*} [options] Override http request options. */ search(spaceId, query, options = {}) { const url = '/internal-transfer-bank-transaction/search'; let queryParams = {}; let headers = Object.assign({}, this._defaultHeaders); // verify required parameter 'spaceId' is not null or undefined if (spaceId === null || spaceId === undefined) { throw new Error('Required parameter spaceId was null or undefined when calling search.'); } // verify required parameter 'query' is not null or undefined if (query === null || query === undefined) { throw new Error('Required parameter query was null or undefined when calling search.'); } if (spaceId !== undefined) { queryParams['spaceId'] = ObjectSerializer_1.ObjectSerializer.serialize(spaceId, "number"); } headers['Content-Type'] = 'application/json;charset=utf-8'; Object.assign(headers, options.headers); let defaultHeaders = { "x-meta-sdk-version": "4.7.0", "x-meta-sdk-language": "typescript", "x-meta-sdk-provider": "wallee", "x-meta-sdk-language-version": this.getVersion(), }; Object.assign(headers, defaultHeaders); let requestConfig = { url, method: 'POST', baseURL: this._basePath, headers, params: queryParams, data: query, timeout: this._timeout * 1000, responseType: 'json', }; const axiosInstance = axios.default.create(); axiosInstance.interceptors.request.use(this._defaultAuthentication); return new Promise((resolve, reject) => { axiosInstance.request(requestConfig) .then(success => { let body; body = ObjectSerializer_1.ObjectSerializer.deserialize(success.data, "Array<InternalTransferBankTransaction>"); return resolve({ response: success.request.res, body: body }); }, failure => { var _a, _b, _c, _d, _e; let errorObject; if ((_a = failure.response) === null || _a === void 0 ? void 0 : _a.status) { if (failure.response.status >= 400 && failure.response.status <= 499) { errorObject = new ClientError_1.ClientError(); } else if (failure.response.status >= 500 && failure.response.status <= 599) { errorObject = new ServerError_1.ServerError(); } else { errorObject = new Object(); } } else { errorObject = new Object(); } return reject({ errorType: errorObject.constructor.name, date: (new Date()).toDateString(), statusCode: ((_b = failure.response) === null || _b === void 0 ? void 0 : _b.status) && isNaN(failure.response.status) ? String(failure.response.status) : "Unknown", statusMessage: ((_c = failure.response) === null || _c === void 0 ? void 0 : _c.statusText) != null ? failure.response.statusText : "Unknown", body: (_d = failure.response) === null || _d === void 0 ? void 0 : _d.data, response: (_e = failure.response) === null || _e === void 0 ? void 0 : _e.request.res }); }) .catch(error => { return reject(error); }); }); } ; } exports.InternalTransferBankTransactionService = InternalTransferBankTransactionService;