76 lines
2.0 KiB
Plaintext
76 lines
2.0 KiB
Plaintext
import { useDataSource, useQueryKey } from "@erp/core/hooks";
|
|
import { IListCustomersResponseDTO } from "@erp/customers/common/dto";
|
|
|
|
export type UseCustomersListParams = Omit<IGetListDataProviderParams, "filters" | "resource"> & {
|
|
status?: string;
|
|
enabled?: boolean;
|
|
queryOptions?: Record<string, unknown>;
|
|
};
|
|
|
|
export type UseCustomersListResponse = UseListQueryResult<
|
|
IListResponseDTO<IListCustomersResponseDTO>,
|
|
unknown
|
|
>;
|
|
|
|
export type UseCustomersGetParamsType = {
|
|
enabled?: boolean;
|
|
queryOptions?: Record<string, unknown>;
|
|
};
|
|
|
|
export type UseCustomersReportParamsType = {
|
|
enabled?: boolean;
|
|
queryOptions?: Record<string, unknown>;
|
|
};
|
|
|
|
export const useCustomers = () => {
|
|
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
|
|
*/
|
|
useList: (params: UseCustomersListParams): UseCustomersListResponse => {
|
|
const dataSource = useDataSource();
|
|
const keys = useQueryKey();
|
|
|
|
const {
|
|
pagination,
|
|
status = "draft",
|
|
quickSearchTerm = undefined,
|
|
enabled = true,
|
|
queryOptions,
|
|
} = params;
|
|
|
|
return useList({
|
|
queryKey: keys().data().resource("customers").action("list").params(params).get(),
|
|
queryFn: () => {
|
|
return dataSource.getList({
|
|
resource: "customers",
|
|
quickSearchTerm,
|
|
filters:
|
|
status !== "all"
|
|
? [
|
|
{
|
|
field: "status",
|
|
operator: "eq",
|
|
value: status,
|
|
},
|
|
]
|
|
: [
|
|
{
|
|
field: "status",
|
|
operator: "ne",
|
|
value: "archived",
|
|
},
|
|
],
|
|
pagination,
|
|
});
|
|
},
|
|
enabled,
|
|
queryOptions,
|
|
});
|
|
},
|
|
};
|
|
return actions;
|
|
};
|