84 lines
2.0 KiB
Dart
84 lines
2.0 KiB
Dart
import 'dart:convert';
|
|
|
|
class AuthResponseModel {
|
|
final String? token;
|
|
final User? user;
|
|
|
|
AuthResponseModel({
|
|
this.token,
|
|
this.user,
|
|
});
|
|
|
|
factory AuthResponseModel.fromJson(String str) =>
|
|
AuthResponseModel.fromMap(json.decode(str));
|
|
|
|
String toJson() => json.encode(toMap());
|
|
|
|
factory AuthResponseModel.fromMap(Map<String, dynamic> json) =>
|
|
AuthResponseModel(
|
|
token: json["token"],
|
|
user: json["user"] == null ? null : User.fromMap(json["user"]),
|
|
);
|
|
|
|
Map<String, dynamic> toMap() => {
|
|
"token": token,
|
|
"user": user?.toMap(),
|
|
};
|
|
}
|
|
|
|
class User {
|
|
final String? id;
|
|
final String? organizationId;
|
|
String? outletId;
|
|
final String? name;
|
|
final String? email;
|
|
final String? role;
|
|
final bool? isActive;
|
|
final DateTime? createdAt;
|
|
final DateTime? updatedAt;
|
|
|
|
User({
|
|
this.id,
|
|
this.organizationId,
|
|
this.outletId,
|
|
this.name,
|
|
this.role,
|
|
this.isActive,
|
|
this.email,
|
|
this.createdAt,
|
|
this.updatedAt,
|
|
});
|
|
|
|
factory User.fromJson(String str) => User.fromMap(json.decode(str));
|
|
|
|
String toJson() => json.encode(toMap());
|
|
|
|
factory User.fromMap(Map<String, dynamic> json) => User(
|
|
id: json["id"],
|
|
organizationId: json["organization_id"],
|
|
outletId: json["outlet_id"],
|
|
name: json["name"],
|
|
email: json["email"],
|
|
role: json["role"],
|
|
isActive: json["is_active"],
|
|
createdAt: json["created_at"] == null
|
|
? null
|
|
: DateTime.parse(json["created_at"]),
|
|
updatedAt: json["updated_at"] == null
|
|
? null
|
|
: DateTime.parse(json["updated_at"]),
|
|
);
|
|
|
|
Map<String, dynamic> toMap() => {
|
|
"id": id,
|
|
"organization_id": organizationId,
|
|
"outlet_id": outletId,
|
|
"name": name,
|
|
"email": email,
|
|
"role": role,
|
|
"is_active": isActive,
|
|
"created_at": createdAt?.toIso8601String(),
|
|
"updated_at": updatedAt?.toIso8601String(),
|
|
};
|
|
}
|