UNPKG

@avonjs/avonjs

Version:

A fluent Node.js API generator.

46 lines (45 loc) 1.33 kB
"use strict"; 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 SelectFilter extends Filter_1.default { /** * The help text for the filter. */ helpText = 'Select value to filter records.'; /** * Apply the filter into the given repository. */ apply(request, repository, value) { if (this.options().includes(value) || this.isValidNullValue(value)) { repository.where({ key: this.filterableAttribute(request), operator: Contracts_1.Operator.eq, value: this.isValidNullValue(value) ? null : value, }); } } /** * Get the possible filtering values. */ options() { return []; } /** * Get the swagger-ui schema. */ schema(request) { return { type: 'array', items: { oneOf: [{ type: 'string' }, { type: 'number' }], enum: this.options(), }, nullable: this.isNullable(), }; } } exports.default = SelectFilter;