@avonjs/avonjs
Version:
A fluent Node.js API generator.
42 lines (41 loc) • 1.25 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Contracts_1 = require("../Contracts");
const Filter_1 = __importDefault(require("./Filter"));
class TextFilter extends Filter_1.default {
/**
* The help text for the filter.
*/
helpText = 'Enter text to search within records.';
/**
* Apply the filter into the given repository.
*/
apply(request, repository, value) {
repository.where({
key: this.filterableAttribute(request),
operator: this.isValidNullValue(value) ? Contracts_1.Operator.eq : Contracts_1.Operator.like,
value: this.isValidNullValue(value)
? null
: this.formatSearchValue(value),
});
}
/**
* Format given value for search.
*/
formatSearchValue(value) {
return value.match(/%/) ? value : `%${value}%`;
}
/**
* Get the swagger-ui schema.
*/
schema(request) {
return {
type: 'string',
nullable: this.isNullable(),
};
}
}
exports.default = TextFilter;