@multiversx/sdk-nestjs-http
Version:
Multiversx SDK Nestjs http package
42 lines • 1.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.QueryCheckInterceptor = void 0;
const tslib_1 = require("tslib");
const common_1 = require("@nestjs/common");
const core_1 = require("@nestjs/core");
let QueryCheckInterceptor = class QueryCheckInterceptor {
constructor(httpAdapterHost) {
this.httpAdapterHost = httpAdapterHost;
}
intercept(context, next) {
const contextType = context.getType();
if (!["http", "https"].includes(contextType)) {
return next.handle();
}
const httpAdapter = this.httpAdapterHost.httpAdapter;
const request = context.switchToHttp().getRequest();
if (httpAdapter.getRequestMethod(request) !== 'GET') {
return next.handle();
}
const metadata = Reflect.getOwnMetadata('__routeArguments__', context.getClass(), context.getHandler().name);
if (!metadata) {
return next.handle();
}
const supportedQueryNames = Object.values(metadata).map((x) => x.data);
for (const paramName of Object.keys(request.query)) {
if (!['fields', 'extract', 'excludeFields'].includes(paramName) && !supportedQueryNames.includes(paramName)) {
delete request.query[paramName];
}
}
const queryParams = new URLSearchParams(request.query).toString();
const queryParamsUrl = queryParams ? `?${queryParams}` : '';
request.guestCacheUrl = `${request.baseUrl}${request.path}${queryParamsUrl}`;
return next.handle();
}
};
QueryCheckInterceptor = tslib_1.__decorate([
(0, common_1.Injectable)(),
tslib_1.__metadata("design:paramtypes", [core_1.HttpAdapterHost])
], QueryCheckInterceptor);
exports.QueryCheckInterceptor = QueryCheckInterceptor;
//# sourceMappingURL=query.check.interceptor.js.map