Formateo
This commit is contained in:
parent
8d0002bfb4
commit
c77705b8b6
@ -1,4 +1,4 @@
|
|||||||
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";
|
||||||
@ -8,7 +8,7 @@ export class Criteria {
|
|||||||
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();
|
||||||
@ -20,13 +20,13 @@ export class Criteria {
|
|||||||
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
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
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;
|
||||||
|
|||||||
@ -23,7 +23,7 @@ export class 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)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
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))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ 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 {
|
||||||
|
|||||||
@ -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