Uecko_ERP/packages/rdx-criteria/src/critera.ts

58 lines
1.6 KiB
TypeScript
Raw Normal View History

2025-11-16 19:29:07 +00:00
import { Criteria as BaseCriteria, Filters, type FiltersPrimitives, Order } from "./codelytv";
2025-06-24 18:38:57 +00:00
import { INITIAL_PAGE_INDEX, INITIAL_PAGE_SIZE } from "./defaults";
2025-05-26 14:45:03 +00:00
export class Criteria extends BaseCriteria {
/**
* Creates a new Criteria instance.
*
2025-09-30 10:59:32 +00:00
* @param quickSearch - 'Quicksearch' field.
2025-05-26 14:45:03 +00:00
* @param filters - The filters to apply.
* @param order - The order to apply.
* @param pageSize - The size of the page.
* @param pageNumber - The number of the page.
2025-09-30 10:59:32 +00:00
*
2025-05-26 14:45:03 +00:00
*/
2025-09-30 10:59:32 +00:00
protected constructor(
2025-05-26 14:45:03 +00:00
public readonly filters: Filters,
public readonly order: Order,
public readonly pageSize: number,
2025-09-30 10:59:32 +00:00
public readonly pageNumber: number,
public readonly quickSearch?: string //Texto libre para búsqueda rápida
2025-05-26 14:45:03 +00:00
) {
super(filters, order, pageSize, pageNumber);
}
static fromPrimitives(
filters: FiltersPrimitives[],
orderBy: string | null,
orderType: string | null,
pageSize: number | null,
2025-09-30 10:59:32 +00:00
pageNumber: number | null,
quickSearch?: string | null
2025-06-24 18:38:57 +00:00
): Criteria {
2025-05-26 14:45:03 +00:00
return new Criteria(
2025-06-24 18:38:57 +00:00
Filters.fromPrimitives(filters),
Order.fromPrimitives(orderBy, orderType),
pageSize ?? INITIAL_PAGE_SIZE,
2025-09-30 10:59:32 +00:00
pageNumber ?? INITIAL_PAGE_INDEX,
quickSearch ?? undefined
2025-05-26 14:45:03 +00:00
);
2025-06-24 18:38:57 +00:00
}
2025-09-11 15:14:51 +00:00
toPrimitives() {
2025-06-24 18:38:57 +00:00
return {
2025-09-30 10:59:32 +00:00
q: this.quickSearch ?? "",
2025-06-24 18:38:57 +00:00
filters: this.filters.toPrimitives(),
2025-09-11 15:14:51 +00:00
orderBy: this.order.orderBy.value,
orderType: this.order.orderType.value,
2025-06-24 18:38:57 +00:00
pageSize: this.pageSize,
pageNumber: this.pageNumber,
};
}
2025-09-11 15:14:51 +00:00
toJSON() {
return this.toPrimitives();
}
2025-05-26 14:45:03 +00:00
}