40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
/**
|
|
* 积分历史记录模型 - 对应后端 CreditsHistoryData schema
|
|
* 原始 Dart: CreditsHistoryData (lib/data/models/user/user.dart)
|
|
*/
|
|
import { z } from "zod";
|
|
|
|
export const CreditsHistoryDataSchema = z.object({
|
|
records: z.array(z.record(z.string(), z.unknown())),
|
|
total: z.number(),
|
|
limit: z.number(),
|
|
offset: z.number(),
|
|
});
|
|
|
|
export type CreditsHistoryDataInput = z.input<typeof CreditsHistoryDataSchema>;
|
|
export type CreditsHistoryDataData = z.output<typeof CreditsHistoryDataSchema>;
|
|
|
|
export class CreditsHistoryData {
|
|
declare readonly records: Record<string, unknown>[];
|
|
declare readonly total: number;
|
|
declare readonly limit: number;
|
|
declare readonly offset: number;
|
|
|
|
private constructor(data: CreditsHistoryDataData) {
|
|
Object.assign(this, data);
|
|
Object.freeze(this);
|
|
}
|
|
|
|
static from(input: CreditsHistoryDataInput): CreditsHistoryData {
|
|
return new CreditsHistoryData(CreditsHistoryDataSchema.parse(input));
|
|
}
|
|
|
|
static fromJson(json: unknown): CreditsHistoryData {
|
|
return CreditsHistoryData.from(json as CreditsHistoryDataInput);
|
|
}
|
|
|
|
toJson(): CreditsHistoryDataData {
|
|
return CreditsHistoryDataSchema.parse(this);
|
|
}
|
|
}
|