Uecko_ERP/modules/customers/src/web/hooks/use-customers-query.tsx

23 lines
718 B
TypeScript
Raw Normal View History

2025-08-23 11:57:48 +00:00
import { useDataSource, useQueryKey } from "@erp/core/hooks";
2025-09-16 17:29:37 +00:00
import { ListCustomersResponseDTO } from "@erp/customer-invoices/common";
2025-08-11 17:49:52 +00:00
import { useQuery } from "@tanstack/react-query";
2025-07-17 18:04:00 +00:00
2025-08-11 17:49:52 +00:00
// Obtener todas las facturas
2025-09-16 17:29:37 +00:00
export const useCustomersQuery = (params?: any) => {
2025-07-17 18:04:00 +00:00
const dataSource = useDataSource();
const keys = useQueryKey();
2025-09-16 17:29:37 +00:00
return useQuery<ListCustomersResponseDTO>({
2025-07-17 18:04:00 +00:00
queryKey: keys().data().resource("customers").action("list").params(params).get(),
2025-09-16 17:29:37 +00:00
queryFn: async (context) => {
2025-07-17 18:04:00 +00:00
const { signal } = context;
2025-09-16 17:29:37 +00:00
const customers = await dataSource.getList("customers", {
2025-07-17 18:04:00 +00:00
signal,
...params,
});
2025-09-16 17:29:37 +00:00
return customers as ListCustomersResponseDTO;
2025-07-17 18:04:00 +00:00
},
});
};