ente/lib/models/api/collection/user.dart
Neeraj Gupta 5aae4f4157 refactor: move user class in separate file
Signed-off-by: Neeraj Gupta <254676+ua741@users.noreply.github.com>
2023-05-23 11:24:35 +05:30

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));
}