40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
/**
|
|
* 登录响应
|
|
* 原始 Dart: LoginResponse (lib/data/models/auth/auth_response.dart)
|
|
*/
|
|
import { z } from "zod";
|
|
import { User, UserSchema } from "../user/user";
|
|
|
|
export const LoginResponseSchema = z.object({
|
|
user: UserSchema,
|
|
token: z.string(),
|
|
refreshToken: z.string().default(""),
|
|
});
|
|
|
|
export type LoginResponseInput = z.input<typeof LoginResponseSchema>;
|
|
export type LoginResponseData = z.output<typeof LoginResponseSchema>;
|
|
|
|
export class LoginResponse {
|
|
declare readonly user: User;
|
|
declare readonly token: string;
|
|
declare readonly refreshToken: string;
|
|
|
|
private constructor(input: LoginResponseInput) {
|
|
const data = LoginResponseSchema.parse(input);
|
|
Object.assign(this, data);
|
|
Object.freeze(this);
|
|
}
|
|
|
|
static from(input: LoginResponseInput): LoginResponse {
|
|
return new LoginResponse(input);
|
|
}
|
|
|
|
static fromJson(json: unknown): LoginResponse {
|
|
return LoginResponse.from(json as LoginResponseInput);
|
|
}
|
|
|
|
toJson(): LoginResponseData {
|
|
return LoginResponseSchema.parse(this);
|
|
}
|
|
}
|