UNPKG

@slavmak2486/bx24ts

Version:

Library for bitrix24

73 lines (72 loc) 2.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CallResult = void 0; const lodash_1 = require("lodash"); class CallResult { constructor(data, config, bx24, status) { var _a, _b; this.answer = data; this.query = config; this.status = status; this.bx24 = bx24; if ((_a = this.answer) === null || _a === void 0 ? void 0 : _a.next) { this.answer.next = parseInt(this.answer.next); } if ((_b = this.answer) === null || _b === void 0 ? void 0 : _b.error) { this.answer.ex = new ajaxError(this.status, typeof this.answer.error == 'string' ? this.answer : this.answer.error); } } data() { var _a; return (_a = this.answer) === null || _a === void 0 ? void 0 : _a.result; } error() { var _a; if (this.status !== 200 && this.status !== 201) return `Incorect response: #${this.status}`; return ((_a = this.answer) === null || _a === void 0 ? void 0 : _a.ex) || this.error_description(); } error_description() { return this.answer.error_description; } more() { return !isNaN(this.answer.next); } time() { return this.answer.time; } total() { return parseInt(this.answer.total); } next() { if (!this.more()) return false; const params = (0, lodash_1.cloneDeep)(this.query.data); params.start = this.answer.next; if (this.query.callback) { this.bx24.callMethod(this.query.method, params, this.query.callback); return true; } else { return this.bx24.callMethod(this.query.method, params); } } } exports.CallResult = CallResult; class ajaxError { constructor(status, ex) { this.status = status; this.ex = ex; } getError() { return this.ex; } getStatus() { return this.status; } toString() { return this.ex.error + (this.ex.error_description ? ': ' + this.ex.error_description : '') + ' (' + this.status + ')'; } }