Some checks are pending
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Mobile App CI / test (push) Waiting to run
Mobile App CI / build-android (push) Blocked by required conditions
Mobile App CI / build-ios (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
Deploy Telegram Bot / Deploy Telegram Bot (push) Waiting to run
47 lines
1.9 KiB
Dart
47 lines
1.9 KiB
Dart
import 'package:mnemo_cards_common_backend/mnemo_cards_common_backend.dart';
|
||
import 'package:mnemo_cards_common/mnemo_cards_common.dart';
|
||
|
||
extension UserDataModelExtension on UserDataModel {
|
||
/// Конвертация в DTO с использованием данных из модели
|
||
///
|
||
/// Примечание: packProgress, studyDates, categoryMinutes теперь рассчитываются на лету
|
||
/// и должны передаваться как параметры
|
||
UserDataDto toDto({
|
||
List<PackProgressDto>? calculatedPackProgress,
|
||
List<DateTime>? calculatedStudyDates,
|
||
Map<String, int>? calculatedCategoryMinutes,
|
||
AllWordsStatisticsDto? calculatedWordsStatistics,
|
||
}) {
|
||
return UserDataDto(
|
||
allWordsStatistics:
|
||
calculatedWordsStatistics ??
|
||
AllWordsStatisticsDto(
|
||
words: words.map((model) => model.toDto()).toList(),
|
||
),
|
||
allTestsStatistics: AllTestsStatisticsDto(
|
||
tests: Map.fromEntries(
|
||
testsStatistics.map((model) => MapEntry(model.id!, model.toDto())),
|
||
),
|
||
lastSessionToken: this.lastTestSessionToken,
|
||
),
|
||
// NEW STATISTICS FIELDS
|
||
lastTimeOnline: lastTimeOnline,
|
||
totalStudyTimeMinutes: totalStudyTimeMinutes,
|
||
currentStreak: currentStreak,
|
||
longestStreak: longestStreak,
|
||
packProgress: calculatedPackProgress != null
|
||
? {
|
||
for (final progress in calculatedPackProgress)
|
||
progress.packId: progress,
|
||
}
|
||
: {
|
||
for (final progress in packProgress)
|
||
progress.packId: progress.toDto(),
|
||
},
|
||
studyDates: calculatedStudyDates ?? List<DateTime>.from(studyDates),
|
||
categoryMinutes:
|
||
calculatedCategoryMinutes ?? Map<String, int>.from(categoryMinutes),
|
||
achievements: achievements.map((model) => model.toDto()).toList(),
|
||
);
|
||
}
|
||
}
|