2026-05-09 13:36:49 +08:00

282 lines
9.8 KiB
TypeScript

import { apiRequest } from "@/shared/api/request";
import { API_ENDPOINTS, API_OPERATIONS, apiEndpointPath } from "@/shared/api/generated/endpoints";
export { listRegions } from "@/shared/api/regions";
import type {
AgencyDto,
AgencyJoinEnabledPayload,
ApiList,
ApiPage,
BDProfileDto,
BDStatusPayload,
CoinSellerDto,
CoinSellerStockCreditDto,
CoinSellerStockCreditPayload,
CoinSellerStatusPayload,
CountryDto,
CountryPayload,
CountryUpdatePayload,
CreateAgencyPayload,
CreateAgencyResultDto,
CreateBDLeaderPayload,
CreateBDPayload,
CreateCoinSellerPayload,
EntityId,
HostCommandPayload,
HostProfileDto,
PageQuery,
RegionCountriesPayload,
RegionDto,
RegionPayload,
RegionUpdatePayload,
} from "@/shared/api/types";
export function listCountries(query: PageQuery = {}): Promise<ApiList<CountryDto>> {
const endpoint = API_ENDPOINTS.listCountries;
return apiRequest<ApiList<CountryDto>>(apiEndpointPath(API_OPERATIONS.listCountries), {
method: endpoint.method,
query,
});
}
export function getCountry(countryId: EntityId): Promise<CountryDto> {
const endpoint = API_ENDPOINTS.getCountry;
return apiRequest<CountryDto>(apiEndpointPath(API_OPERATIONS.getCountry, { country_id: countryId }), {
method: endpoint.method,
});
}
export function createCountry(payload: CountryPayload): Promise<CountryDto> {
const endpoint = API_ENDPOINTS.createCountry;
return apiRequest<CountryDto, CountryPayload>(apiEndpointPath(API_OPERATIONS.createCountry), {
body: payload,
method: endpoint.method,
});
}
export function updateCountry(countryId: EntityId, payload: CountryUpdatePayload): Promise<CountryDto> {
const endpoint = API_ENDPOINTS.updateCountry;
return apiRequest<CountryDto, CountryUpdatePayload>(
apiEndpointPath(API_OPERATIONS.updateCountry, { country_id: countryId }),
{
body: payload,
method: endpoint.method,
},
);
}
export function enableCountry(countryId: EntityId): Promise<CountryDto> {
const endpoint = API_ENDPOINTS.enableCountry;
return apiRequest<CountryDto>(apiEndpointPath(API_OPERATIONS.enableCountry, { country_id: countryId }), {
method: endpoint.method,
});
}
export function disableCountry(countryId: EntityId): Promise<CountryDto> {
const endpoint = API_ENDPOINTS.disableCountry;
return apiRequest<CountryDto>(apiEndpointPath(API_OPERATIONS.disableCountry, { country_id: countryId }), {
method: endpoint.method,
});
}
export function deleteCountry(countryId: EntityId): Promise<CountryDto> {
const endpoint = API_ENDPOINTS.deleteCountry;
return apiRequest<CountryDto>(apiEndpointPath(API_OPERATIONS.deleteCountry, { country_id: countryId }), {
method: endpoint.method,
});
}
export function getRegion(regionId: EntityId): Promise<RegionDto> {
const endpoint = API_ENDPOINTS.getRegion;
return apiRequest<RegionDto>(apiEndpointPath(API_OPERATIONS.getRegion, { region_id: regionId }), {
method: endpoint.method,
});
}
export function createRegion(payload: RegionPayload): Promise<RegionDto> {
const endpoint = API_ENDPOINTS.createRegion;
return apiRequest<RegionDto, RegionPayload>(apiEndpointPath(API_OPERATIONS.createRegion), {
body: payload,
method: endpoint.method,
});
}
export function updateRegion(regionId: EntityId, payload: RegionUpdatePayload): Promise<RegionDto> {
const endpoint = API_ENDPOINTS.updateRegion;
return apiRequest<RegionDto, RegionUpdatePayload>(
apiEndpointPath(API_OPERATIONS.updateRegion, { region_id: regionId }),
{
body: payload,
method: endpoint.method,
},
);
}
export function replaceRegionCountries(regionId: EntityId, payload: RegionCountriesPayload): Promise<RegionDto> {
const endpoint = API_ENDPOINTS.replaceRegionCountries;
return apiRequest<RegionDto, RegionCountriesPayload>(
apiEndpointPath(API_OPERATIONS.replaceRegionCountries, { region_id: regionId }),
{
body: payload,
method: endpoint.method,
},
);
}
export function enableRegion(regionId: EntityId): Promise<RegionDto> {
const endpoint = API_ENDPOINTS.enableRegion;
return apiRequest<RegionDto>(apiEndpointPath(API_OPERATIONS.enableRegion, { region_id: regionId }), {
method: endpoint.method,
});
}
export function disableRegion(regionId: EntityId): Promise<RegionDto> {
const endpoint = API_ENDPOINTS.disableRegion;
return apiRequest<RegionDto>(apiEndpointPath(API_OPERATIONS.disableRegion, { region_id: regionId }), {
method: endpoint.method,
});
}
export function listBDLeaders(query: PageQuery = {}): Promise<ApiPage<BDProfileDto>> {
const endpoint = API_ENDPOINTS.listBDLeaders;
return apiRequest<ApiPage<BDProfileDto>>(apiEndpointPath(API_OPERATIONS.listBDLeaders), {
method: endpoint.method,
query,
});
}
export function listBDs(query: PageQuery = {}): Promise<ApiPage<BDProfileDto>> {
const endpoint = API_ENDPOINTS.listBDs;
return apiRequest<ApiPage<BDProfileDto>>(apiEndpointPath(API_OPERATIONS.listBDs), {
method: endpoint.method,
query,
});
}
export function listAgencies(query: PageQuery = {}): Promise<ApiPage<AgencyDto>> {
const endpoint = API_ENDPOINTS.listAgencies;
return apiRequest<ApiPage<AgencyDto>>(apiEndpointPath(API_OPERATIONS.listAgencies), {
method: endpoint.method,
query,
});
}
export function listHosts(query: PageQuery = {}): Promise<ApiPage<HostProfileDto>> {
const endpoint = API_ENDPOINTS.listHosts;
return apiRequest<ApiPage<HostProfileDto>>(apiEndpointPath(API_OPERATIONS.listHosts), {
method: endpoint.method,
query,
});
}
export function listCoinSellers(query: PageQuery = {}): Promise<ApiPage<CoinSellerDto>> {
const endpoint = API_ENDPOINTS.listCoinSellers;
return apiRequest<ApiPage<CoinSellerDto>>(apiEndpointPath(API_OPERATIONS.listCoinSellers), {
method: endpoint.method,
query,
});
}
export function createBDLeader(payload: CreateBDLeaderPayload): Promise<BDProfileDto> {
const endpoint = API_ENDPOINTS.createBDLeader;
return apiRequest<BDProfileDto, CreateBDLeaderPayload>(apiEndpointPath(API_OPERATIONS.createBDLeader), {
body: payload,
method: endpoint.method,
});
}
export function createBD(payload: CreateBDPayload): Promise<BDProfileDto> {
const endpoint = API_ENDPOINTS.createBD;
return apiRequest<BDProfileDto, CreateBDPayload>(apiEndpointPath(API_OPERATIONS.createBD), {
body: payload,
method: endpoint.method,
});
}
export function deleteBDLeader(userId: EntityId): Promise<BDProfileDto> {
return apiRequest<BDProfileDto>(`/v1/admin/bd-leaders/${encodeURIComponent(String(userId))}`, {
method: "DELETE",
});
}
export function setBDLeaderStatus(userId: EntityId, payload: BDStatusPayload): Promise<BDProfileDto> {
const endpoint = API_ENDPOINTS.setBDLeaderStatus;
return apiRequest<BDProfileDto, BDStatusPayload>(
apiEndpointPath(API_OPERATIONS.setBDLeaderStatus, { user_id: userId }),
{
body: payload,
method: endpoint.method,
},
);
}
export function setBDStatus(userId: EntityId, payload: BDStatusPayload): Promise<BDProfileDto> {
const endpoint = API_ENDPOINTS.setBDStatus;
return apiRequest<BDProfileDto, BDStatusPayload>(apiEndpointPath(API_OPERATIONS.setBDStatus, { user_id: userId }), {
body: payload,
method: endpoint.method,
});
}
export function createCoinSeller(payload: CreateCoinSellerPayload): Promise<CoinSellerDto> {
const endpoint = API_ENDPOINTS.createCoinSeller;
return apiRequest<CoinSellerDto, CreateCoinSellerPayload>(apiEndpointPath(API_OPERATIONS.createCoinSeller), {
body: payload,
method: endpoint.method,
});
}
export function setCoinSellerStatus(userId: EntityId, payload: CoinSellerStatusPayload): Promise<CoinSellerDto> {
const endpoint = API_ENDPOINTS.setCoinSellerStatus;
return apiRequest<CoinSellerDto, CoinSellerStatusPayload>(
apiEndpointPath(API_OPERATIONS.setCoinSellerStatus, { user_id: userId }),
{
body: payload,
method: endpoint.method,
},
);
}
export function creditCoinSellerStock(
userId: EntityId,
payload: CoinSellerStockCreditPayload,
): Promise<CoinSellerStockCreditDto> {
const endpoint = API_ENDPOINTS.creditCoinSellerStock;
return apiRequest<CoinSellerStockCreditDto, CoinSellerStockCreditPayload>(
apiEndpointPath(API_OPERATIONS.creditCoinSellerStock, { user_id: userId }),
{
body: payload,
method: endpoint.method,
},
);
}
export function createAgency(payload: CreateAgencyPayload): Promise<CreateAgencyResultDto> {
const endpoint = API_ENDPOINTS.createAgency;
return apiRequest<CreateAgencyResultDto, CreateAgencyPayload>(apiEndpointPath(API_OPERATIONS.createAgency), {
body: payload,
method: endpoint.method,
});
}
export function closeAgency(agencyId: EntityId, payload: HostCommandPayload): Promise<AgencyDto> {
const endpoint = API_ENDPOINTS.closeAgency;
return apiRequest<AgencyDto, HostCommandPayload>(
apiEndpointPath(API_OPERATIONS.closeAgency, { agency_id: agencyId }),
{
body: payload,
method: endpoint.method,
},
);
}
export function setAgencyJoinEnabled(agencyId: EntityId, payload: AgencyJoinEnabledPayload): Promise<AgencyDto> {
const endpoint = API_ENDPOINTS.setAgencyJoinEnabled;
return apiRequest<AgencyDto, AgencyJoinEnabledPayload>(
apiEndpointPath(API_OPERATIONS.setAgencyJoinEnabled, { agency_id: agencyId }),
{
body: payload,
method: endpoint.method,
},
);
}