Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
intercept(context: ExecutionContext, next: CallHandler) {
const req = context.switchToHttp().getRequest();
try {
/* istanbul ignore else */
if (!req[PARSED_CRUD_REQUEST_KEY]) {
const { ctrlOptions, crudOptions, action } = this.getCrudInfo(context);
const parser = RequestQueryParser.create();
parser.parseQuery(req.query);
if (!isNil(ctrlOptions)) {
const search = this.getSearch(parser, crudOptions, action, req.params);
const auth = this.getAuth(parser, crudOptions, req);
parser.search = auth.or
? { $or: [auth.or, { $and: search }] }
: { $and: [auth.filter, ...search] };
} else {
parser.search = { $and: this.getSearch(parser, crudOptions, action) };
}
req[PARSED_CRUD_REQUEST_KEY] = this.getCrudRequest(parser, crudOptions);
}
const convertDataRequestToHTTP = (type, resource, params) => {
let url = '';
const options = {};
switch (type) {
case GET_LIST: {
const { page, perPage } = params.pagination;
const query = RequestQueryBuilder
.create({
filter: composeFilter(params.filter),
})
.setLimit(perPage)
.setPage(page)
.sortBy(params.sort)
.setOffset((page - 1) * perPage)
.query();
url = `${apiUrl}/${resource}?${query}`;
break;
}
case GET_ONE: {
url = `${apiUrl}/${resource}/${params.id}`;
url = `${apiUrl}/${resource}?${query}`;
break;
}
case GET_MANY_REFERENCE: {
const { page, perPage } = params.pagination;
const filter = composeFilter(params.filter);
filter.push({
field: params.target,
operator: CondOperator.EQUALS,
value: params.id,
});
const query = RequestQueryBuilder
.create({
filter,
})
.sortBy(params.sort)
.setLimit(perPage)
.setOffset((page - 1) * perPage)
.query();
url = `${apiUrl}/${resource}?${query}`;
break;
}
case UPDATE: {
url = `${apiUrl}/${resource}/${params.id}`;
options.method = 'PATCH';
options.body = JSON.stringify(params.data);