Formateo
This commit is contained in:
parent
8d0002bfb4
commit
c77705b8b6
@ -1,44 +1,44 @@
|
|||||||
import { FiltersPrimitives } from "./Filter";
|
import type { FiltersPrimitives } from "./Filter";
|
||||||
import { Filters } from "./Filters";
|
import { Filters } from "./Filters";
|
||||||
import { InvalidCriteria } from "./InvalidCriteria";
|
import { InvalidCriteria } from "./InvalidCriteria";
|
||||||
import { Order } from "./Order";
|
import { Order } from "./Order";
|
||||||
|
|
||||||
export class Criteria {
|
export class Criteria {
|
||||||
constructor(
|
constructor(
|
||||||
public readonly filters: Filters,
|
public readonly filters: Filters,
|
||||||
public readonly order: Order,
|
public readonly order: Order,
|
||||||
public readonly pageSize: number | null,
|
public readonly pageSize: number | null,
|
||||||
public readonly pageNumber: number | null,
|
public readonly pageNumber: number | null
|
||||||
) {
|
) {
|
||||||
if (pageNumber !== null && pageSize === null) {
|
if (pageNumber !== null && pageSize === null) {
|
||||||
throw new InvalidCriteria();
|
throw new InvalidCriteria();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromPrimitives(
|
static fromPrimitives(
|
||||||
filters: FiltersPrimitives[],
|
filters: FiltersPrimitives[],
|
||||||
orderBy: string | null,
|
orderBy: string | null,
|
||||||
orderType: string | null,
|
orderType: string | null,
|
||||||
pageSize: number | null,
|
pageSize: number | null,
|
||||||
pageNumber: number | null,
|
pageNumber: number | null
|
||||||
): Criteria {
|
): Criteria {
|
||||||
return new Criteria(
|
return new Criteria(
|
||||||
Filters.fromPrimitives(filters),
|
Filters.fromPrimitives(filters),
|
||||||
Order.fromPrimitives(orderBy, orderType),
|
Order.fromPrimitives(orderBy, orderType),
|
||||||
pageSize,
|
pageSize,
|
||||||
pageNumber,
|
pageNumber
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static withFilters(filters: FiltersPrimitives[]): Criteria {
|
static withFilters(filters: FiltersPrimitives[]): Criteria {
|
||||||
return Criteria.fromPrimitives(filters, null, null, null, null);
|
return Criteria.fromPrimitives(filters, null, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
hasOrder(): boolean {
|
hasOrder(): boolean {
|
||||||
return !this.order.isNone();
|
return !this.order.isNone();
|
||||||
}
|
}
|
||||||
|
|
||||||
hasFilters(): boolean {
|
hasFilters(): boolean {
|
||||||
return !this.filters.isEmpty();
|
return !this.filters.isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
24
packages/rdx-criteria/src/codelytv/Filter.d.ts
vendored
24
packages/rdx-criteria/src/codelytv/Filter.d.ts
vendored
@ -1,17 +1,17 @@
|
|||||||
import { FilterField } from "./FilterField";
|
import type { FilterField } from "./FilterField";
|
||||||
import { FilterOperator } from "./FilterOperator";
|
import type { FilterOperator } from "./FilterOperator";
|
||||||
import { FilterValue } from "./FilterValue";
|
import type { FilterValue } from "./FilterValue";
|
||||||
export type FiltersPrimitives = {
|
export type FiltersPrimitives = {
|
||||||
field: string;
|
field: string;
|
||||||
operator: string;
|
operator: string;
|
||||||
value: string;
|
value: string;
|
||||||
};
|
};
|
||||||
export declare class Filter {
|
export declare class Filter {
|
||||||
readonly field: FilterField;
|
readonly field: FilterField;
|
||||||
readonly operator: FilterOperator;
|
readonly operator: FilterOperator;
|
||||||
readonly value: FilterValue;
|
readonly value: FilterValue;
|
||||||
constructor(field: FilterField, operator: FilterOperator, value: FilterValue);
|
constructor(field: FilterField, operator: FilterOperator, value: FilterValue);
|
||||||
static fromPrimitives(field: string, operator: string, value: string): Filter;
|
static fromPrimitives(field: string, operator: string, value: string): Filter;
|
||||||
toPrimitives(): FiltersPrimitives;
|
toPrimitives(): FiltersPrimitives;
|
||||||
}
|
}
|
||||||
//# sourceMappingURL=Filter.d.ts.map
|
//# sourceMappingURL=Filter.d.ts.map
|
||||||
@ -3,35 +3,35 @@ import { FilterOperator, Operator } from "./FilterOperator";
|
|||||||
import { FilterValue } from "./FilterValue";
|
import { FilterValue } from "./FilterValue";
|
||||||
|
|
||||||
export type FiltersPrimitives = {
|
export type FiltersPrimitives = {
|
||||||
field: string;
|
field: string;
|
||||||
operator: string;
|
operator: string;
|
||||||
value: string;
|
value: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Filter {
|
export class Filter {
|
||||||
readonly field: FilterField;
|
readonly field: FilterField;
|
||||||
readonly operator: FilterOperator;
|
readonly operator: FilterOperator;
|
||||||
readonly value: FilterValue;
|
readonly value: FilterValue;
|
||||||
|
|
||||||
constructor(field: FilterField, operator: FilterOperator, value: FilterValue) {
|
constructor(field: FilterField, operator: FilterOperator, value: FilterValue) {
|
||||||
this.field = field;
|
this.field = field;
|
||||||
this.operator = operator;
|
this.operator = operator;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromPrimitives(field: string, operator: string, value: string): Filter {
|
static fromPrimitives(field: string, operator: string, value: string): Filter {
|
||||||
return new Filter(
|
return new Filter(
|
||||||
new FilterField(field),
|
new FilterField(field),
|
||||||
new FilterOperator(Operator[operator as keyof typeof Operator]),
|
new FilterOperator(Operator[operator as keyof typeof Operator]),
|
||||||
new FilterValue(value),
|
new FilterValue(value)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
toPrimitives(): FiltersPrimitives {
|
toPrimitives(): FiltersPrimitives {
|
||||||
return {
|
return {
|
||||||
field: this.field.value,
|
field: this.field.value,
|
||||||
operator: this.operator.value,
|
operator: this.operator.value,
|
||||||
value: this.value.value,
|
value: this.value.value,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
export class FilterField {
|
export class FilterField {
|
||||||
constructor(public readonly value: string) {}
|
constructor(public readonly value: string) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,42 +1,42 @@
|
|||||||
export enum Operator {
|
export enum Operator {
|
||||||
EQUAL = "=",
|
EQUAL = "=",
|
||||||
NOT_EQUAL = "!=",
|
NOT_EQUAL = "!=",
|
||||||
GREATER_THAN = ">",
|
GREATER_THAN = ">",
|
||||||
GREATER_THAN_OR_EQUAL = ">=",
|
GREATER_THAN_OR_EQUAL = ">=",
|
||||||
LOWER_THAN = "<",
|
LOWER_THAN = "<",
|
||||||
LOWER_THAN_OR_EQUAL = "<=",
|
LOWER_THAN_OR_EQUAL = "<=",
|
||||||
CONTAINS = "CONTAINS",
|
CONTAINS = "CONTAINS",
|
||||||
NOT_CONTAINS = "NOT_CONTAINS",
|
NOT_CONTAINS = "NOT_CONTAINS",
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FilterOperator {
|
export class FilterOperator {
|
||||||
constructor(public readonly value: Operator) {}
|
constructor(public readonly value: Operator) {}
|
||||||
|
|
||||||
isContains(): boolean {
|
isContains(): boolean {
|
||||||
return this.value.valueOf() === Operator.CONTAINS.valueOf();
|
return this.value.valueOf() === Operator.CONTAINS.valueOf();
|
||||||
}
|
}
|
||||||
|
|
||||||
isNotContains(): boolean {
|
isNotContains(): boolean {
|
||||||
return this.value.valueOf() === Operator.NOT_CONTAINS.valueOf();
|
return this.value.valueOf() === Operator.NOT_CONTAINS.valueOf();
|
||||||
}
|
}
|
||||||
|
|
||||||
isNotEquals(): boolean {
|
isNotEquals(): boolean {
|
||||||
return this.value.valueOf() === Operator.NOT_EQUAL.valueOf();
|
return this.value.valueOf() === Operator.NOT_EQUAL.valueOf();
|
||||||
}
|
}
|
||||||
|
|
||||||
isGreaterThan(): boolean {
|
isGreaterThan(): boolean {
|
||||||
return this.value.valueOf() === Operator.GREATER_THAN.valueOf();
|
return this.value.valueOf() === Operator.GREATER_THAN.valueOf();
|
||||||
}
|
}
|
||||||
|
|
||||||
isGreaterThanOrEqual(): boolean {
|
isGreaterThanOrEqual(): boolean {
|
||||||
return this.value.valueOf() === Operator.GREATER_THAN_OR_EQUAL.valueOf();
|
return this.value.valueOf() === Operator.GREATER_THAN_OR_EQUAL.valueOf();
|
||||||
}
|
}
|
||||||
|
|
||||||
isLowerThan(): boolean {
|
isLowerThan(): boolean {
|
||||||
return this.value.valueOf() === Operator.LOWER_THAN.valueOf();
|
return this.value.valueOf() === Operator.LOWER_THAN.valueOf();
|
||||||
}
|
}
|
||||||
|
|
||||||
isLowerThanOrEqual(): boolean {
|
isLowerThanOrEqual(): boolean {
|
||||||
return this.value.valueOf() === Operator.LOWER_THAN_OR_EQUAL.valueOf();
|
return this.value.valueOf() === Operator.LOWER_THAN_OR_EQUAL.valueOf();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
export class FilterValue {
|
export class FilterValue {
|
||||||
constructor(public readonly value: string) {}
|
constructor(public readonly value: string) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,19 +1,19 @@
|
|||||||
import { Filter, FiltersPrimitives } from "./Filter";
|
import { Filter, type FiltersPrimitives } from "./Filter";
|
||||||
|
|
||||||
export class Filters {
|
export class Filters {
|
||||||
constructor(public readonly value: Filter[]) {}
|
constructor(public readonly value: Filter[]) {}
|
||||||
|
|
||||||
static fromPrimitives(filters: FiltersPrimitives[]): Filters {
|
static fromPrimitives(filters: FiltersPrimitives[]): Filters {
|
||||||
return new Filters(
|
return new Filters(
|
||||||
filters.map((filter) => Filter.fromPrimitives(filter.field, filter.operator, filter.value)),
|
filters.map((filter) => Filter.fromPrimitives(filter.field, filter.operator, filter.value))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
toPrimitives(): FiltersPrimitives[] {
|
toPrimitives(): FiltersPrimitives[] {
|
||||||
return this.value.map((filter) => filter.toPrimitives());
|
return this.value.map((filter) => filter.toPrimitives());
|
||||||
}
|
}
|
||||||
|
|
||||||
isEmpty(): boolean {
|
isEmpty(): boolean {
|
||||||
return this.value.length === 0;
|
return this.value.length === 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
export class InvalidCriteria extends Error {
|
export class InvalidCriteria extends Error {
|
||||||
constructor() {
|
constructor() {
|
||||||
super("Page size is required when page number is defined");
|
super("Page size is required when page number is defined");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,22 +2,22 @@ import { OrderBy } from "./OrderBy";
|
|||||||
import { OrderType, OrderTypes } from "./OrderType";
|
import { OrderType, OrderTypes } from "./OrderType";
|
||||||
|
|
||||||
export class Order {
|
export class Order {
|
||||||
constructor(
|
constructor(
|
||||||
public readonly orderBy: OrderBy,
|
public readonly orderBy: OrderBy,
|
||||||
public readonly orderType: OrderType,
|
public readonly orderType: OrderType
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
static none(): Order {
|
static none(): Order {
|
||||||
return new Order(new OrderBy(""), new OrderType(OrderTypes.NONE));
|
return new Order(new OrderBy(""), new OrderType(OrderTypes.NONE));
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromPrimitives(orderBy: string | null, orderType: string | null): Order {
|
static fromPrimitives(orderBy: string | null, orderType: string | null): Order {
|
||||||
return orderBy !== null
|
return orderBy !== null
|
||||||
? new Order(new OrderBy(orderBy), new OrderType(orderType as OrderTypes))
|
? new Order(new OrderBy(orderBy), new OrderType(orderType as OrderTypes))
|
||||||
: Order.none();
|
: Order.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
isNone(): boolean {
|
isNone(): boolean {
|
||||||
return this.orderType.isNone();
|
return this.orderType.isNone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
export class OrderBy {
|
export class OrderBy {
|
||||||
constructor(public readonly value: string) {}
|
constructor(public readonly value: string) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
export enum OrderTypes {
|
export enum OrderTypes {
|
||||||
ASC = "ASC",
|
ASC = "ASC",
|
||||||
DESC = "DESC",
|
DESC = "DESC",
|
||||||
NONE = "NONE",
|
NONE = "NONE",
|
||||||
}
|
}
|
||||||
|
|
||||||
export class OrderType {
|
export class OrderType {
|
||||||
constructor(public readonly value: OrderTypes) {}
|
constructor(public readonly value: OrderTypes) {}
|
||||||
|
|
||||||
isNone(): boolean {
|
isNone(): boolean {
|
||||||
return this.value === OrderTypes.NONE;
|
return this.value === OrderTypes.NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { Criteria as BaseCriteria, Filters, FiltersPrimitives, Order } from "./codelytv";
|
import { Criteria as BaseCriteria, Filters, type FiltersPrimitives, Order } from "./codelytv";
|
||||||
import { INITIAL_PAGE_INDEX, INITIAL_PAGE_SIZE } from "./defaults";
|
import { INITIAL_PAGE_INDEX, INITIAL_PAGE_SIZE } from "./defaults";
|
||||||
|
|
||||||
export class Criteria extends BaseCriteria {
|
export class Criteria extends BaseCriteria {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { FiltersPrimitives } from "./codelytv";
|
import type { FiltersPrimitives } from "./codelytv";
|
||||||
import { Criteria } from "./critera";
|
import { Criteria } from "./critera";
|
||||||
import { DEFAULT_ORDER, INITIAL_PAGE_INDEX, INITIAL_PAGE_SIZE } from "./defaults";
|
import { DEFAULT_ORDER, INITIAL_PAGE_INDEX, INITIAL_PAGE_SIZE } from "./defaults";
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ export class CriteriaFromUrlConverter {
|
|||||||
searchParams.forEach((value, key) => {
|
searchParams.forEach((value, key) => {
|
||||||
const match = key.match(/filters\[(\d+)]\[(.+)]/);
|
const match = key.match(/filters\[(\d+)]\[(.+)]/);
|
||||||
if (match) {
|
if (match) {
|
||||||
const index = match[1];
|
const index = match[1]!;
|
||||||
const property = match[2] as keyof FiltersPrimitives;
|
const property = match[2] as keyof FiltersPrimitives;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||||
if (!tempFilters[index]) {
|
if (!tempFilters[index]) {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { FindOptions, Sequelize } from "sequelize";
|
import type { FindOptions, Sequelize } from "sequelize";
|
||||||
import { Criteria } from "./critera.js";
|
|
||||||
|
import type { Criteria } from "./critera.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mapeo lógico→físico de campos.
|
* Mapeo lógico→físico de campos.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user