refactor(data): replace schema classes with readonly models
This commit is contained in:
@@ -3,16 +3,17 @@
|
||||
*
|
||||
* 支付 / 付费墙相关远程调用。
|
||||
*/
|
||||
import type { IPaymentRepository } from "@/data/repositories/interfaces";
|
||||
import {
|
||||
CreatePaymentOrderRequest,
|
||||
CreatePaymentOrderRequestSchema,
|
||||
CreatePaymentOrderResponse,
|
||||
PayChannel,
|
||||
PaymentOrderStatusResponse,
|
||||
PaymentPlansResponse,
|
||||
PaymentPlansResponseSchema,
|
||||
} from "@/data/schemas/payment";
|
||||
import { PaymentApi, paymentApi } from "@/data/services/api";
|
||||
import { PaymentPlansStorage } from "@/data/storage/payment";
|
||||
import type { IPaymentRepository } from "@/data/repositories/interfaces";
|
||||
import { Result } from "@/utils/result";
|
||||
import { createLazySingleton } from "./lazy_singleton";
|
||||
|
||||
@@ -23,7 +24,7 @@ export class PaymentRepository implements IPaymentRepository {
|
||||
async getPlans(): Promise<Result<PaymentPlansResponse>> {
|
||||
return Result.wrap(async () => {
|
||||
const response = await this.api.getPlans();
|
||||
await PaymentPlansStorage.setPlans(response.toJson());
|
||||
await PaymentPlansStorage.setPlans(response);
|
||||
return response;
|
||||
});
|
||||
}
|
||||
@@ -33,7 +34,7 @@ export class PaymentRepository implements IPaymentRepository {
|
||||
return Result.wrap(async () => {
|
||||
const result = await PaymentPlansStorage.getPlans();
|
||||
if (Result.isErr(result)) throw result.error;
|
||||
return result.data ? PaymentPlansResponse.from(result.data) : null;
|
||||
return result.data ? PaymentPlansResponseSchema.parse(result.data) : null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -41,9 +42,9 @@ export class PaymentRepository implements IPaymentRepository {
|
||||
async getTipPlans(): Promise<Result<PaymentPlansResponse>> {
|
||||
return Result.wrap(async () => {
|
||||
const response = await this.api.getTipPlans();
|
||||
return PaymentPlansResponse.from({
|
||||
return PaymentPlansResponseSchema.parse({
|
||||
plans: response.plans.map((plan) => ({
|
||||
...plan.toJson(),
|
||||
...plan,
|
||||
orderType: "tip",
|
||||
vipDays: null,
|
||||
dolAmount: null,
|
||||
@@ -72,7 +73,7 @@ export class PaymentRepository implements IPaymentRepository {
|
||||
payChannel: PayChannel,
|
||||
autoRenew: boolean,
|
||||
): Promise<Result<CreatePaymentOrderResponse>> {
|
||||
const request = CreatePaymentOrderRequest.from({
|
||||
const request = CreatePaymentOrderRequestSchema.parse({
|
||||
planId,
|
||||
payChannel,
|
||||
autoRenew,
|
||||
@@ -86,7 +87,6 @@ export class PaymentRepository implements IPaymentRepository {
|
||||
): Promise<Result<PaymentOrderStatusResponse>> {
|
||||
return Result.wrap(() => this.api.getOrderStatus(orderId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** 全局懒单例。 */
|
||||
|
||||
Reference in New Issue
Block a user