@egodigital/egoose
Version:
Helper classes and functions for Node.js 10 or later.
75 lines • 2.48 kB
JavaScript
;
/**
* This file is part of the @egodigital/egoose distribution.
* Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/)
*
* @egodigital/egoose is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, version 3.
*
* @egodigital/egoose is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("../index");
const _ = require("lodash");
/**
* A basic statistic provider.
*/
class StatisticProviderBase {
/** @inheritdoc */
async close() {
}
/** @inheritdoc */
async load(opts) {
opts = index_1.cloneObj(opts || {});
// offset
opts.offset = parseInt(index_1.toStringSafe(opts.offset)
.trim());
if (isNaN(opts.offset)) {
opts.offset = 0; // default
}
opts.offset = Math.max(0, opts.offset);
// limit
opts.limit = parseInt(index_1.toStringSafe(opts.limit)
.trim());
if (isNaN(opts.limit)) {
opts.limit = 25; // default
}
if (opts.limit < 1) {
opts.limit = false; // no limit
}
const RESULT = {
rows: [],
};
await this.loadInner(opts, RESULT);
// rows
RESULT.rows = index_1.asArray(RESULT.rows);
// offset
if (_.isNil(RESULT.offset)) {
RESULT.offset = opts.offset;
}
// totalCount
if (_.isNil(RESULT.totalCount)) {
RESULT.totalCount = RESULT.rows.length;
}
// hasMore
if (_.isNil(RESULT.hasMore)) {
if (false === opts.limit) {
RESULT.hasMore = false;
}
else {
RESULT.hasMore = RESULT.rows.length >= opts.limit;
}
}
RESULT.hasMore = index_1.toBooleanSafe(RESULT.hasMore);
return RESULT;
}
}
exports.StatisticProviderBase = StatisticProviderBase;
//# sourceMappingURL=index.js.map