refactor(data): replace schema classes with readonly models

This commit is contained in:
2026-07-17 13:21:40 +08:00
parent 3437312167
commit ae97366a4a
103 changed files with 1220 additions and 2117 deletions
+11 -12
View File
@@ -6,9 +6,13 @@
import {
CreatePaymentOrderRequest,
CreatePaymentOrderResponse,
CreatePaymentOrderResponseSchema,
PaymentOrderStatusResponse,
PaymentOrderStatusResponseSchema,
PaymentPlansResponse,
PaymentPlansResponseSchema,
TipPaymentPlansResponse,
TipPaymentPlansResponseSchema,
} from "@/data/schemas/payment";
import { ApiPath } from "./api_path";
@@ -21,17 +25,15 @@ export class PaymentApi {
*/
async getPlans(): Promise<PaymentPlansResponse> {
const env = await httpClient<ApiEnvelope<unknown>>(ApiPath.paymentPlans);
return PaymentPlansResponse.fromJson(
return PaymentPlansResponseSchema.parse(
unwrap(env) as Record<string, unknown>,
);
}
/** 获取咖啡打赏套餐列表。 */
async getTipPlans(): Promise<TipPaymentPlansResponse> {
const env = await httpClient<ApiEnvelope<unknown>>(
ApiPath.paymentTipPlans,
);
return TipPaymentPlansResponse.fromJson(
const env = await httpClient<ApiEnvelope<unknown>>(ApiPath.paymentTipPlans);
return TipPaymentPlansResponseSchema.parse(
unwrap(env) as Record<string, unknown>,
);
}
@@ -46,10 +48,10 @@ export class PaymentApi {
ApiPath.paymentCreateOrder,
{
method: "POST",
body: body.toJson(),
body,
},
);
return CreatePaymentOrderResponse.fromJson(
return CreatePaymentOrderResponseSchema.parse(
unwrap(env) as Record<string, unknown>,
);
}
@@ -57,20 +59,17 @@ export class PaymentApi {
/**
* 查询支付订单状态
*/
async getOrderStatus(
orderId: string,
): Promise<PaymentOrderStatusResponse> {
async getOrderStatus(orderId: string): Promise<PaymentOrderStatusResponse> {
const env = await httpClient<ApiEnvelope<unknown>>(
ApiPath.paymentOrderStatus,
{
query: { order_id: orderId },
},
);
return PaymentOrderStatusResponse.fromJson(
return PaymentOrderStatusResponseSchema.parse(
unwrap(env) as Record<string, unknown>,
);
}
}
/**