mnemo_cards/mnemo_cards_backend/lib/user/user_data_model.dart
Dmitry 4f29ccd3c8
Some checks are pending
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Deploy Admin Panel / Deploy Admin Panel (push) Waiting to run
Deploy Admin Panel / Admin Panel Verification (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
backaend + admin
2025-12-14 23:45:27 +03:00

40 lines
1.8 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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