Skip to content

Commit

Permalink
Fix method fetchList()
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-tech committed Mar 13, 2023
1 parent 67d5764 commit f62811d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/bx24-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,31 +183,31 @@ class BX24Wrapper {
* @param {string} method Списочный метод запроса
* @param {object} params Параметры запроса
* @param {function} dataExtractor Функция для извлечения данных из результатов запроса
* @param {string} idKey Имя поля ID сущности ('ID' или 'id')
*
* @return {object} Generator
*
* @see https://dev.1c-bitrix.ru/rest_help/js_library/rest/callMethod.php BX24.callMethod
*/
async *fetchList(method, params = {}, dataExtractor = null) {
async *fetchList(method, params = {}, dataExtractor = null, idKey = 'ID') {
params.order = params.order || {};
params.filter = params.filter || {};
params.start = -1;

let idKey = 'id' in params.order ? 'id' : 'ID';
let moreIdKey = '>' + idKey,
counter = 0,
total = 0;

params.order[ idKey ] = 'ASC';
params.filter[ '>' . idKey ] = 0;

let counter = 0,
total = 0;
params.filter[ moreIdKey ] = 0;

this.progress(0);

do {
let data = await this.callMethod(method, params, dataExtractor),
result = this.lastResult;

if (params.filter[ '>' . idKey ] === 0) {
if (params.filter[ moreIdKey ] === 0) {
total = result.total();
}

Expand All @@ -224,7 +224,7 @@ class BX24Wrapper {
break;
}

params.filter[ '>' . idKey ] = data[ data.length - 1 ][ idKey ];
params.filter[ moreIdKey ] = data[ data.length - 1 ][ idKey ];

} while (true);
}
Expand Down

0 comments on commit f62811d

Please sign in to comment.