Some checks failed
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Web App CI / test (push) Waiting to run
Web App CI / build (push) Blocked by required conditions
Deploy Mnemo Cards / Deploy Backend (push) Waiting to run
Deploy Mnemo Cards / Deploy Web App (push) Blocked by required conditions
Deploy Mnemo Cards / Final Verification (push) Blocked by required conditions
Mobile App CI / test (push) Has been cancelled
Deploy Telegram Bot / Deploy Telegram Bot (push) Has been cancelled
Mobile App CI / build-android (push) Has been cancelled
Mobile App CI / build-ios (push) Has been cancelled
41 lines
1.3 KiB
Dart
41 lines
1.3 KiB
Dart
import 'package:drift/drift.dart' as drift;
|
|
import 'package:mnemo_cards_backend/database/database.dart';
|
|
import 'package:mnemo_cards_backend/packs/card_pack_drift_extension.dart';
|
|
import 'package:mnemo_cards_common_backend/mnemo_cards_common_backend.dart';
|
|
|
|
/// Extension для конвертации User (Drift) в UserModel
|
|
extension UserToUserModel on User {
|
|
Future<UserModel> toUserModel([List<CardPack>? packs]) async {
|
|
final packModels = packs != null
|
|
? await Future.wait(packs.map((p) => p.toModel()))
|
|
: <CardPackModel>[];
|
|
final userModel = UserModel(
|
|
id: id,
|
|
name: name,
|
|
email: email,
|
|
telegram: telegram,
|
|
admin: admin,
|
|
purchases: purchases,
|
|
userSettings: userSettings,
|
|
packs: packModels,
|
|
);
|
|
|
|
return userModel;
|
|
}
|
|
}
|
|
|
|
/// Extension для конвертации UserModel в User (Drift)
|
|
extension UserModelToUser on UserModel {
|
|
UsersCompanion toUsersCompanion() {
|
|
return UsersCompanion(
|
|
id: id != null ? drift.Value(id!) : const drift.Value.absent(),
|
|
externalUserId: const drift.Value.absent(),
|
|
name: drift.Value(name),
|
|
email: drift.Value(email),
|
|
telegram: drift.Value(telegram),
|
|
admin: drift.Value(admin),
|
|
purchases: drift.Value(purchases),
|
|
userSettings: drift.Value(userSettings),
|
|
);
|
|
}
|
|
}
|