39 lines
793 B
Dart
39 lines
793 B
Dart
import "dart:convert";
|
|
|
|
class User {
|
|
int? id;
|
|
String email;
|
|
String? name;
|
|
String? role;
|
|
|
|
User({
|
|
this.id,
|
|
required this.email,
|
|
this.name,
|
|
this.role,
|
|
});
|
|
|
|
bool get isViewer => role == null || role?.toUpperCase() == 'VIEWER';
|
|
|
|
bool get isCollaborator =>
|
|
role != null && role?.toUpperCase() == 'COLLABORATOR';
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return {'id': id, 'email': email, 'name': name, 'role': role};
|
|
}
|
|
|
|
static fromMap(Map<String, dynamic>? map) {
|
|
if (map == null) return null;
|
|
|
|
return User(
|
|
id: map['id'],
|
|
email: map['email'],
|
|
name: map['name'],
|
|
role: map['role'] ?? 'VIEWER',
|
|
);
|
|
}
|
|
|
|
String toJson() => json.encode(toMap());
|
|
|
|
factory User.fromJson(String source) => User.fromMap(json.decode(source));
|
|
}
|