49 lines
1.4 KiB
Dart
49 lines
1.4 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:drift/drift.dart';
|
|
|
|
import '../../models/user_profile.dart';
|
|
import 'app_database.dart';
|
|
|
|
UserProfile profileFromRow(UserProfileRow row) {
|
|
return UserProfile(
|
|
firebaseUid: row.firebaseUid,
|
|
email: row.email,
|
|
displayName: row.displayName,
|
|
photoUrl: row.photoUrl,
|
|
locale: row.locale,
|
|
timezone: row.timezone,
|
|
onboardingCompleted: row.onboardingCompleted,
|
|
revision: row.revision,
|
|
updatedAt: row.updatedAt.toUtc(),
|
|
lastSyncedAt: row.lastSyncedAt?.toUtc(),
|
|
dirty: row.dirty,
|
|
);
|
|
}
|
|
|
|
UserProfileRowsCompanion companionFromProfile(UserProfile profile) {
|
|
return UserProfileRowsCompanion(
|
|
firebaseUid: Value<String>(profile.firebaseUid),
|
|
email: Value<String?>(profile.email),
|
|
displayName: Value<String?>(profile.displayName),
|
|
photoUrl: Value<String?>(profile.photoUrl),
|
|
locale: Value<String>(profile.locale),
|
|
timezone: Value<String?>(profile.timezone),
|
|
onboardingCompleted: Value<bool>(profile.onboardingCompleted),
|
|
revision: Value<int>(profile.revision),
|
|
updatedAt: Value<DateTime>(profile.updatedAt.toUtc()),
|
|
lastSyncedAt: Value<DateTime?>(profile.lastSyncedAt?.toUtc()),
|
|
dirty: Value<bool>(profile.dirty),
|
|
);
|
|
}
|
|
|
|
String encodeProfilePayload(UserProfile profile) {
|
|
return jsonEncode(profile.toJson());
|
|
}
|
|
|
|
UserProfile decodeProfilePayload(String json) {
|
|
return UserProfile.fromJson(
|
|
jsonDecode(json) as Map<String, dynamic>,
|
|
);
|
|
}
|