108 lines
3.7 KiB
TypeScript
108 lines
3.7 KiB
TypeScript
import { apiRequest } from "@/shared/api/request";
|
|
import { API_ENDPOINTS, API_OPERATIONS, apiEndpointPath } from "@/shared/api/generated/endpoints";
|
|
import type {
|
|
ApiPage,
|
|
ApiList,
|
|
EntityId,
|
|
PageQuery,
|
|
RechargeBillDto,
|
|
RechargeProductDto,
|
|
RechargeProductPayload,
|
|
ThirdPartyPaymentChannelDto,
|
|
ThirdPartyPaymentMethodDto,
|
|
ThirdPartyPaymentRateSyncDto,
|
|
} from "@/shared/api/types";
|
|
|
|
export function listRechargeBills(query: PageQuery = {}): Promise<ApiPage<RechargeBillDto>> {
|
|
const endpoint = API_ENDPOINTS.listRechargeBills;
|
|
return apiRequest<ApiPage<RechargeBillDto>>(apiEndpointPath(API_OPERATIONS.listRechargeBills), {
|
|
method: endpoint.method,
|
|
query,
|
|
});
|
|
}
|
|
|
|
export function listRechargeProducts(query: PageQuery = {}): Promise<ApiPage<RechargeProductDto>> {
|
|
const endpoint = API_ENDPOINTS.listRechargeProducts;
|
|
return apiRequest<ApiPage<RechargeProductDto>>(apiEndpointPath(API_OPERATIONS.listRechargeProducts), {
|
|
method: endpoint.method,
|
|
query,
|
|
});
|
|
}
|
|
|
|
export function createRechargeProduct(payload: RechargeProductPayload): Promise<RechargeProductDto> {
|
|
const endpoint = API_ENDPOINTS.createRechargeProduct;
|
|
return apiRequest<RechargeProductDto, RechargeProductPayload>(
|
|
apiEndpointPath(API_OPERATIONS.createRechargeProduct),
|
|
{
|
|
body: payload,
|
|
method: endpoint.method,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function updateRechargeProduct(
|
|
productId: EntityId,
|
|
payload: RechargeProductPayload,
|
|
): Promise<RechargeProductDto> {
|
|
const endpoint = API_ENDPOINTS.updateRechargeProduct;
|
|
return apiRequest<RechargeProductDto, RechargeProductPayload>(
|
|
apiEndpointPath(API_OPERATIONS.updateRechargeProduct, { product_id: productId }),
|
|
{
|
|
body: payload,
|
|
method: endpoint.method,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function deleteRechargeProduct(productId: EntityId): Promise<unknown> {
|
|
const endpoint = API_ENDPOINTS.deleteRechargeProduct;
|
|
return apiRequest(apiEndpointPath(API_OPERATIONS.deleteRechargeProduct, { product_id: productId }), {
|
|
method: endpoint.method,
|
|
});
|
|
}
|
|
|
|
export function listThirdPartyPaymentChannels(): Promise<ApiList<ThirdPartyPaymentChannelDto>> {
|
|
const endpoint = API_ENDPOINTS.listThirdPartyPaymentChannels;
|
|
return apiRequest<ApiList<ThirdPartyPaymentChannelDto>>(
|
|
apiEndpointPath(API_OPERATIONS.listThirdPartyPaymentChannels),
|
|
{
|
|
method: endpoint.method,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function setThirdPartyPaymentMethodStatus(
|
|
methodId: EntityId,
|
|
payload: { enabled: boolean },
|
|
): Promise<ThirdPartyPaymentMethodDto> {
|
|
const endpoint = API_ENDPOINTS.setThirdPartyPaymentMethodStatus;
|
|
return apiRequest<ThirdPartyPaymentMethodDto, { enabled: boolean }>(
|
|
apiEndpointPath(API_OPERATIONS.setThirdPartyPaymentMethodStatus, { method_id: methodId }),
|
|
{
|
|
body: payload,
|
|
method: endpoint.method,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function updateThirdPartyPaymentRate(
|
|
methodId: EntityId,
|
|
payload: { usdToCurrencyRate: string },
|
|
): Promise<ThirdPartyPaymentMethodDto> {
|
|
const endpoint = API_ENDPOINTS.updateThirdPartyPaymentRate;
|
|
return apiRequest<ThirdPartyPaymentMethodDto, { usdToCurrencyRate: string }>(
|
|
apiEndpointPath(API_OPERATIONS.updateThirdPartyPaymentRate, { method_id: methodId }),
|
|
{
|
|
body: payload,
|
|
method: endpoint.method,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function syncThirdPartyPaymentRates(): Promise<ThirdPartyPaymentRateSyncDto> {
|
|
const endpoint = API_ENDPOINTS.syncThirdPartyPaymentRates;
|
|
return apiRequest<ThirdPartyPaymentRateSyncDto>(apiEndpointPath(API_OPERATIONS.syncThirdPartyPaymentRates), {
|
|
method: endpoint.method,
|
|
});
|
|
}
|