2026-06-16 16:59:40 +08:00

151 lines
4.7 KiB
TypeScript

import { apiRequest } from "@/shared/api/request";
import { API_ENDPOINTS, API_OPERATIONS, apiEndpointPath } from "@/shared/api/generated/endpoints";
import type {
ApiPage,
CoinAdjustmentCreateDto,
CoinAdjustmentDto,
CoinAdjustmentPayload,
CoinLedgerEntryDto,
CoinLedgerUserDto,
CoinSellerLedgerDto,
PageQuery,
ReportDto,
} from "@/shared/api/types";
export interface GiftDiamondRatioItem {
effectiveRegionId: number;
giftTypeCode: string;
ratioPercent: string;
regionId: number;
status: string;
updatedAtMs?: number;
}
export interface GiftDiamondRatioResponse {
regionId: number;
items: GiftDiamondRatioItem[];
}
export interface FullServerNoticeFanoutPayload {
action_param?: string;
action_type?: string;
aggregate_id?: string;
aggregate_type?: string;
batch_size?: number;
body?: string;
command_id?: string;
country?: string;
expire_at_ms?: number;
icon_url?: string;
image_url?: string;
message_type: "system" | "activity";
metadata_json?: string;
priority?: number;
producer_event_type?: string;
region_id?: number;
sent_at_ms?: number;
summary: string;
target_scope: "all_active_users" | "single_user" | "user_ids" | "region" | "country";
target_user_id?: number;
title: string;
user_ids?: number[];
}
export interface FullServerNoticeFanoutResponse {
command_id: string;
created: boolean;
job_id: string;
message_type: string;
status: string;
target_scope: string;
}
export function listCoinLedger(query: PageQuery = {}): Promise<ApiPage<CoinLedgerEntryDto>> {
const endpoint = API_ENDPOINTS.listCoinLedger;
return apiRequest<ApiPage<CoinLedgerEntryDto>>(apiEndpointPath(API_OPERATIONS.listCoinLedger), {
method: endpoint.method,
query,
});
}
export function listCoinSellerLedger(query: PageQuery = {}): Promise<ApiPage<CoinSellerLedgerDto>> {
const endpoint = API_ENDPOINTS.listCoinSellerLedger;
return apiRequest<ApiPage<CoinSellerLedgerDto>>(apiEndpointPath(API_OPERATIONS.listCoinSellerLedger), {
method: endpoint.method,
query,
});
}
export function exportCoinSellerLedger(query: PageQuery = {}): Promise<Response> {
return apiRequest("/v1/admin/operations/coin-seller-ledger/export", {
method: "GET",
query,
raw: true,
});
}
export function listCoinAdjustments(query: PageQuery = {}): Promise<ApiPage<CoinAdjustmentDto>> {
const endpoint = API_ENDPOINTS.listCoinAdjustments;
return apiRequest<ApiPage<CoinAdjustmentDto>>(apiEndpointPath(API_OPERATIONS.listCoinAdjustments), {
method: endpoint.method,
query,
});
}
export function listReports(query: PageQuery = {}): Promise<ApiPage<ReportDto>> {
const endpoint = API_ENDPOINTS.listReports;
return apiRequest<ApiPage<ReportDto>>(apiEndpointPath(API_OPERATIONS.listReports), {
method: endpoint.method,
query,
});
}
export function lookupCoinAdjustmentTarget(userId: string): Promise<CoinLedgerUserDto> {
const endpoint = API_ENDPOINTS.lookupCoinAdjustmentTarget;
return apiRequest<CoinLedgerUserDto>(apiEndpointPath(API_OPERATIONS.lookupCoinAdjustmentTarget), {
method: endpoint.method,
query: { user_id: userId },
});
}
export function createCoinAdjustment(payload: CoinAdjustmentPayload): Promise<CoinAdjustmentCreateDto> {
const endpoint = API_ENDPOINTS.createCoinAdjustment;
return apiRequest<CoinAdjustmentCreateDto, CoinAdjustmentPayload>(
apiEndpointPath(API_OPERATIONS.createCoinAdjustment),
{
body: payload,
method: endpoint.method,
},
);
}
export function getGiftDiamondRatios(regionId: string | number): Promise<GiftDiamondRatioResponse> {
return apiRequest<GiftDiamondRatioResponse>("/v1/admin/operations/gift-diamond-ratios", {
method: "GET",
query: { region_id: regionId },
});
}
export function updateGiftDiamondRatios(payload: {
regionId: number;
ratios: Record<string, string>;
}): Promise<GiftDiamondRatioResponse> {
return apiRequest<GiftDiamondRatioResponse, typeof payload>("/v1/admin/operations/gift-diamond-ratios", {
body: payload,
method: "PUT",
});
}
export function createFullServerNoticeFanout(
payload: FullServerNoticeFanoutPayload,
): Promise<FullServerNoticeFanoutResponse> {
const endpoint = API_ENDPOINTS.createFullServerNoticeFanout;
return apiRequest<FullServerNoticeFanoutResponse, FullServerNoticeFanoutPayload>(
apiEndpointPath(API_OPERATIONS.createFullServerNoticeFanout),
{
body: payload,
method: endpoint.method,
},
);
}