UNPKG

@avonjs/avonjs

Version:

A fluent Node.js API generator.

29 lines (28 loc) 995 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Contracts_1 = require("../Contracts"); exports.default = (Parent) => { class OrderableFields extends Parent { /** * Indicates if the field is nullable. */ acceptsNullValues = true; /** * Apply the filter into the given repository. */ async apply(request, queryBuilder, direction) { if (!Object.values(Contracts_1.Direction).includes(direction) && this.isValidNullValue(direction)) { return; } return this.field.applyOrdering(request, queryBuilder, Contracts_1.Direction.ASC === direction ? Contracts_1.Direction.ASC : Contracts_1.Direction.DESC); } /** * Get the query parameter key for filter. */ key() { return `${this.field.constructor.name}:${this.field.attribute}`; } } return OrderableFields; };