@multiversx/sdk-nestjs-http
Version:
Multiversx SDK Nestjs http package
24 lines • 996 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PaginationInterceptor = void 0;
const common_1 = require("@nestjs/common");
class PaginationInterceptor {
constructor(maxSize = 10000) {
this.maxSize = maxSize;
}
intercept(context, next) {
const contextType = context.getType();
if (!["http", "https"].includes(contextType)) {
return next.handle();
}
const request = context.getArgByIndex(0);
const from = parseInt(request.query.from || 0);
const size = parseInt(request.query.size || 25);
if (from + size > this.maxSize) {
throw new common_1.HttpException(`Result window is too large, from + size must be less than or equal to: [${this.maxSize}] but was [${from + size}]`, common_1.HttpStatus.BAD_REQUEST);
}
return next.handle();
}
}
exports.PaginationInterceptor = PaginationInterceptor;
//# sourceMappingURL=pagination.interceptor.js.map