Uecko_ERP/modules/customer-invoices/src/web/hooks/use-customer-invoices.bak

76 lines
2.1 KiB
Plaintext
Raw Normal View History

2025-08-23 11:57:48 +00:00
import { useDataSource, useQueryKey } from "@erp/core/hooks";
2025-06-12 06:55:17 +00:00
import { IListCustomerInvoicesResponseDTO } from "@erp/customerInvoices/common/dto";
2025-05-19 11:59:13 +00:00
2025-06-11 15:13:44 +00:00
export type UseCustomerInvoicesListParams = Omit<IGetListDataProviderParams, "filters" | "resource"> & {
2025-05-19 11:59:13 +00:00
status?: string;
enabled?: boolean;
queryOptions?: Record<string, unknown>;
};
2025-06-11 15:13:44 +00:00
export type UseCustomerInvoicesListResponse = UseListQueryResult<
IListResponseDTO<IListCustomerInvoicesResponseDTO>,
2025-05-19 11:59:13 +00:00
unknown
>;
2025-06-11 15:13:44 +00:00
export type UseCustomerInvoicesGetParamsType = {
2025-05-19 11:59:13 +00:00
enabled?: boolean;
queryOptions?: Record<string, unknown>;
};
2025-06-11 15:13:44 +00:00
export type UseCustomerInvoicesReportParamsType = {
2025-05-19 11:59:13 +00:00
enabled?: boolean;
queryOptions?: Record<string, unknown>;
};
2025-06-11 15:13:44 +00:00
export const useCustomerInvoices = () => {
2025-05-19 11:59:13 +00:00
const actions = {
/**
* Hook para obtener la lista de facturas
* @param params - Parámetros para la consulta de la lista de facturas
* @returns - Respuesta de la consulta de la lista de facturas
*/
2025-06-11 15:13:44 +00:00
useList: (params: UseCustomerInvoicesListParams): UseCustomerInvoicesListResponse => {
2025-05-19 11:59:13 +00:00
const dataSource = useDataSource();
const keys = useQueryKey();
const {
pagination,
status = "draft",
quickSearchTerm = undefined,
enabled = true,
queryOptions,
} = params;
return useList({
2025-06-12 06:55:17 +00:00
queryKey: keys().data().resource("customerInvoices").action("list").params(params).get(),
2025-05-19 11:59:13 +00:00
queryFn: () => {
return dataSource.getList({
2025-06-12 06:55:17 +00:00
resource: "customerInvoices",
2025-05-19 11:59:13 +00:00
quickSearchTerm,
filters:
status !== "all"
? [
{
field: "status",
operator: "eq",
value: status,
},
]
: [
{
field: "status",
operator: "ne",
value: "archived",
},
],
pagination,
});
},
enabled,
queryOptions,
});
},
};
return actions;
};