repos
Some checks are pending
Backend CI / test (push) Waiting to run
Backend 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
Some checks are pending
Backend CI / test (push) Waiting to run
Backend 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
This commit is contained in:
parent
a6abcfa7e6
commit
e3afe9888c
6 changed files with 87 additions and 70 deletions
|
|
@ -76,9 +76,6 @@ extension GetItInjectableX on _i174.GetIt {
|
|||
() => _i222.RustorePurchaseHandler(),
|
||||
);
|
||||
gh.lazySingleton<_i972.GoogleApi>(() => const _i972.GoogleApi());
|
||||
gh.lazySingleton<_i368.AdminAnalyticsApiV2>(
|
||||
() => _i368.AdminAnalyticsApiV2(),
|
||||
);
|
||||
gh.lazySingleton<_i240.TelegramAuthCodeService>(
|
||||
() => _i240.TelegramAuthCodeService(),
|
||||
);
|
||||
|
|
@ -107,21 +104,12 @@ extension GetItInjectableX on _i174.GetIt {
|
|||
gh.lazySingleton<_i108.JwtService>(
|
||||
() => _i108.JwtService(gh<_i1072.AppDatabase>()),
|
||||
);
|
||||
gh.lazySingleton<_i891.DiscountsManager>(
|
||||
() => _i891.DiscountsManager(gh<_i1072.AppDatabase>()),
|
||||
);
|
||||
gh.lazySingleton<_i258.PackRepository>(
|
||||
() => _i258.PackRepository(gh<_i1072.AppDatabase>()),
|
||||
);
|
||||
gh.lazySingleton<_i802.AchievementManager>(
|
||||
() => _i802.AchievementManager(gh<_i1072.AppDatabase>()),
|
||||
);
|
||||
gh.lazySingleton<_i71.SessionTracker>(
|
||||
() => _i71.SessionTracker(gh<_i1072.AppDatabase>()),
|
||||
);
|
||||
gh.lazySingleton<_i1029.StatisticsCalculator>(
|
||||
() => _i1029.StatisticsCalculator(gh<_i1072.AppDatabase>()),
|
||||
);
|
||||
gh.lazySingleton<_i909.WordStatisticsManager>(
|
||||
() => _i909.WordStatisticsManager(gh<_i1072.AppDatabase>()),
|
||||
);
|
||||
|
|
@ -131,21 +119,33 @@ extension GetItInjectableX on _i174.GetIt {
|
|||
gh.lazySingleton<_i950.UserRepository>(
|
||||
() => _i950.UserRepository(gh<_i1072.AppDatabase>()),
|
||||
);
|
||||
gh.factory<_i1015.AdminPacksApiV2>(
|
||||
() => _i1015.AdminPacksApiV2(gh<_i1072.AppDatabase>()),
|
||||
);
|
||||
gh.lazySingleton<_i964.SubscriptionsApiV2>(
|
||||
() => _i964.SubscriptionsApiV2(gh<_i377.SubscriptionManager>()),
|
||||
);
|
||||
gh.lazySingleton<_i858.DiscountsApiV2>(
|
||||
() => _i858.DiscountsApiV2(gh<_i891.DiscountsManager>()),
|
||||
);
|
||||
gh.lazySingleton<_i296.TelegramBotApiV2>(
|
||||
() => _i296.TelegramBotApiV2(
|
||||
gh<_i1072.AppDatabase>(),
|
||||
gh<_i950.UserRepository>(),
|
||||
),
|
||||
);
|
||||
gh.lazySingleton<_i891.DiscountsManager>(
|
||||
() => _i891.DiscountsManager(
|
||||
gh<_i1072.AppDatabase>(),
|
||||
gh<_i950.UserRepository>(),
|
||||
),
|
||||
);
|
||||
gh.lazySingleton<_i802.AchievementManager>(
|
||||
() => _i802.AchievementManager(
|
||||
gh<_i1072.AppDatabase>(),
|
||||
gh<_i950.UserRepository>(),
|
||||
),
|
||||
);
|
||||
gh.lazySingleton<_i1029.StatisticsCalculator>(
|
||||
() => _i1029.StatisticsCalculator(
|
||||
gh<_i1072.AppDatabase>(),
|
||||
gh<_i950.UserRepository>(),
|
||||
),
|
||||
);
|
||||
gh.factory<_i895.AdminUsersApiV2>(
|
||||
() => _i895.AdminUsersApiV2(
|
||||
gh<_i1072.AppDatabase>(),
|
||||
|
|
@ -172,19 +172,16 @@ extension GetItInjectableX on _i174.GetIt {
|
|||
gh<_i1009.PaymentManager>(),
|
||||
),
|
||||
);
|
||||
gh.lazySingleton<_i1062.FreePacksDistributor>(
|
||||
() => _i1062.FreePacksDistributor(
|
||||
gh.factory<_i1015.AdminPacksApiV2>(
|
||||
() => _i1015.AdminPacksApiV2(
|
||||
gh<_i1072.AppDatabase>(),
|
||||
gh<_i258.PackRepository>(),
|
||||
),
|
||||
);
|
||||
gh.lazySingleton<_i560.UserManager>(
|
||||
() => _i560.UserManager(
|
||||
gh.lazySingleton<_i368.AdminAnalyticsApiV2>(
|
||||
() => _i368.AdminAnalyticsApiV2(
|
||||
gh<_i950.UserRepository>(),
|
||||
gh<_i1072.AppDatabase>(),
|
||||
gh<_i1062.FreePacksDistributor>(),
|
||||
gh<_i71.SessionTracker>(),
|
||||
gh<_i1029.StatisticsCalculator>(),
|
||||
gh<_i802.AchievementManager>(),
|
||||
),
|
||||
);
|
||||
gh.lazySingleton<_i273.PromocodesApiV2>(
|
||||
|
|
@ -193,7 +190,13 @@ extension GetItInjectableX on _i174.GetIt {
|
|||
gh.lazySingleton<_i908.ProductsPriceResolver>(
|
||||
() => _i908.ProductsPriceResolver(
|
||||
gh<_i891.DiscountsManager>(),
|
||||
gh<_i1072.AppDatabase>(),
|
||||
gh<_i950.UserRepository>(),
|
||||
),
|
||||
);
|
||||
gh.lazySingleton<_i1062.FreePacksDistributor>(
|
||||
() => _i1062.FreePacksDistributor(
|
||||
gh<_i950.UserRepository>(),
|
||||
gh<_i258.PackRepository>(),
|
||||
),
|
||||
);
|
||||
gh.lazySingleton<_i735.CheckPaymentTask>(
|
||||
|
|
@ -202,6 +205,9 @@ extension GetItInjectableX on _i174.GetIt {
|
|||
gh<_i1072.AppDatabase>(),
|
||||
),
|
||||
);
|
||||
gh.lazySingleton<_i858.DiscountsApiV2>(
|
||||
() => _i858.DiscountsApiV2(gh<_i891.DiscountsManager>()),
|
||||
);
|
||||
gh.lazySingleton<_i280.UserManager>(
|
||||
() => _i280.UserManager(
|
||||
gh<_i1072.AppDatabase>(),
|
||||
|
|
@ -213,6 +219,15 @@ extension GetItInjectableX on _i174.GetIt {
|
|||
gh<_i909.WordStatisticsManager>(),
|
||||
),
|
||||
);
|
||||
gh.lazySingleton<_i247.UsersApiV2>(
|
||||
() => _i247.UsersApiV2(
|
||||
gh<_i280.UserManager>(),
|
||||
gh<_i1009.PaymentManager>(),
|
||||
gh<_i1029.StatisticsCalculator>(),
|
||||
gh<_i950.UserRepository>(),
|
||||
gh<_i1072.AppDatabase>(),
|
||||
),
|
||||
);
|
||||
gh.lazySingleton<_i483.AdminAuthApiV2>(
|
||||
() => _i483.AdminAuthApiV2(
|
||||
gh<_i240.TelegramAuthCodeService>(),
|
||||
|
|
@ -233,24 +248,36 @@ extension GetItInjectableX on _i174.GetIt {
|
|||
gh<_i433.PackDtoConverter>(),
|
||||
),
|
||||
);
|
||||
gh.lazySingleton<_i69.PurchasesApiV2>(
|
||||
() => _i69.PurchasesApiV2(
|
||||
gh<_i1009.PaymentManager>(),
|
||||
gh<_i833.PackManager>(),
|
||||
gh.lazySingleton<_i560.UserManager>(
|
||||
() => _i560.UserManager(
|
||||
gh<_i1072.AppDatabase>(),
|
||||
gh<_i1062.FreePacksDistributor>(),
|
||||
gh<_i71.SessionTracker>(),
|
||||
gh<_i1029.StatisticsCalculator>(),
|
||||
gh<_i802.AchievementManager>(),
|
||||
),
|
||||
);
|
||||
gh.lazySingleton<_i561.MnemoShelf>(
|
||||
() => _i561.MnemoShelf(gh<_i280.UserManager>()),
|
||||
);
|
||||
gh.lazySingleton<_i247.UsersApiV2>(
|
||||
() => _i247.UsersApiV2(
|
||||
gh<_i280.UserManager>(),
|
||||
gh.lazySingleton<_i69.PurchasesApiV2>(
|
||||
() => _i69.PurchasesApiV2(
|
||||
gh<_i1009.PaymentManager>(),
|
||||
gh<_i1029.StatisticsCalculator>(),
|
||||
gh<_i833.PackManager>(),
|
||||
gh<_i950.UserRepository>(),
|
||||
gh<_i1072.AppDatabase>(),
|
||||
),
|
||||
);
|
||||
gh.lazySingleton<_i800.PacksApiV2>(
|
||||
() => _i800.PacksApiV2(
|
||||
gh<_i833.PackManager>(),
|
||||
gh<_i259.TestManager>(),
|
||||
gh<_i258.PackRepository>(),
|
||||
gh<_i950.UserRepository>(),
|
||||
gh<_i1072.AppDatabase>(),
|
||||
gh<_i747.MinioService>(),
|
||||
),
|
||||
);
|
||||
gh.lazySingleton<_i170.TestsApiV2>(
|
||||
() => _i170.TestsApiV2(
|
||||
gh<_i259.TestManager>(),
|
||||
|
|
@ -267,14 +294,6 @@ extension GetItInjectableX on _i174.GetIt {
|
|||
gh<_i240.TelegramAuthCodeService>(),
|
||||
),
|
||||
);
|
||||
gh.lazySingleton<_i800.PacksApiV2>(
|
||||
() => _i800.PacksApiV2(
|
||||
gh<_i833.PackManager>(),
|
||||
gh<_i259.TestManager>(),
|
||||
gh<_i1072.AppDatabase>(),
|
||||
gh<_i747.MinioService>(),
|
||||
),
|
||||
);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ class PaymentManager {
|
|||
}
|
||||
|
||||
// Получить пользователя
|
||||
final userModel = await _userRepository.getUserWithDataById(payment.userId);
|
||||
final userModel = await _userRepository.getUserById(payment.userId, withData: true);
|
||||
if (userModel == null) {
|
||||
log('User not found: ${payment.userId}');
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -258,7 +258,7 @@ class UsersApiV2 {
|
|||
}
|
||||
|
||||
// Convert UserData to UserDataDto
|
||||
final userDataModel = await _userRepository.getUserWithDataById(user.id!);
|
||||
final userDataModel = await _userRepository.getUserById(user.id!, withData: true);
|
||||
if (userDataModel?.userData == null) {
|
||||
return _json({'error': 'user_data_not_found'}, statusCode: 404);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,10 +10,9 @@ class CheckAdminsTask with task.Task {
|
|||
@override
|
||||
String get name => 'check_admins';
|
||||
|
||||
final AppDatabase _db;
|
||||
final UserRepository _userRepository;
|
||||
|
||||
CheckAdminsTask(this._db, this._userRepository);
|
||||
CheckAdminsTask(this._userRepository);
|
||||
|
||||
@override
|
||||
Future<void> task() async {
|
||||
|
|
@ -28,16 +27,15 @@ class CheckAdminsTask with task.Task {
|
|||
print('$name processing admin ID: $externalUserId');
|
||||
if (externalUserId.isNotEmpty) {
|
||||
// Найти токен по externalUserId
|
||||
final token = await _db.userDao.getTokenByExternalUserId(
|
||||
externalUserId,
|
||||
);
|
||||
final rawUser = await _userRepository.getUserByExternalId(externalUserId);
|
||||
final userId = rawUser?.id;
|
||||
|
||||
if (token == null) {
|
||||
if (userId == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Получить пользователя по userId из токена
|
||||
final user = await _userRepository.getUserById(token.userId);
|
||||
final user = await _userRepository.getUserById(userId);
|
||||
if (user != null && user.id != null) {
|
||||
adminIds.add(user.id!);
|
||||
if (!user.admin) {
|
||||
|
|
@ -53,8 +51,6 @@ class CheckAdminsTask with task.Task {
|
|||
}
|
||||
}
|
||||
}
|
||||
// TODO: Implement logic to remove admin flag from users not in adminIdsList
|
||||
// if needed in the future
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import 'package:mnemo_cards_backend/database/database.dart';
|
|||
import 'package:mnemo_cards_backend/discounts/discounts_manager.dart';
|
||||
import 'package:mnemo_cards_backend/user/user_manager.dart';
|
||||
import 'package:mnemo_cards_backend/tests/test_manager.dart';
|
||||
import 'package:mnemo_cards_backend/user/user_repository.dart';
|
||||
|
||||
import 'api/di/injector.dart';
|
||||
import 'cron/check_admins.dart';
|
||||
|
|
@ -120,9 +121,9 @@ void main() async {
|
|||
// ignore: unawaited_futures
|
||||
CronManager([
|
||||
DeleteOldArchives(),
|
||||
CheckAdminsTask(database),
|
||||
CheckAdminsTask(getIt.get<UserRepository>()),
|
||||
getIt.get<CheckPaymentTask>(),
|
||||
AddFreePacks(getIt.get<FreePacksDistributor>(), database),
|
||||
AddFreePacks(getIt.get<FreePacksDistributor>(), getIt.get<UserRepository>()),
|
||||
Backup(backupDir),
|
||||
GeneratePromocodes(database),
|
||||
DiscountCampaignTask(getIt.get<DiscountsManager>(), database),
|
||||
|
|
|
|||
|
|
@ -17,10 +17,24 @@ class UserRepository {
|
|||
|
||||
/// Получить пользователя по ID
|
||||
/// [includePacks] - загружать ли связанные паки пользователя
|
||||
/// [withData] - загружать ли UserData пользователя
|
||||
Future<UserModel?> getUserById(
|
||||
String id, {
|
||||
bool includePacks = false,
|
||||
bool withData = true,
|
||||
}) async {
|
||||
if (withData) {
|
||||
final userWithData = await _db.userDao.getUserWithDataById(id);
|
||||
if (userWithData == null) return null;
|
||||
|
||||
if (includePacks) {
|
||||
final packs = await _db.userDao.getUserPacks(id);
|
||||
return await userWithData.user.toUserModel(packs);
|
||||
}
|
||||
|
||||
return await userWithData.user.toUserModel();
|
||||
}
|
||||
|
||||
final user = await _db.userDao.getUserById(id);
|
||||
if (user == null) return null;
|
||||
|
||||
|
|
@ -43,25 +57,12 @@ class UserRepository {
|
|||
/// Получить пользователя по externalUserId
|
||||
Future<UserModel?> getUserByExternalId(String externalId) async {
|
||||
final user = await _db.userDao.getUserByExternalId(externalId);
|
||||
|
||||
if (user == null) return null;
|
||||
|
||||
return await user.toUserModel();
|
||||
}
|
||||
|
||||
/// Получить пользователя с UserData
|
||||
Future<UserModel?> getUserWithDataById(String id) async {
|
||||
final userWithData = await _db.userDao.getUserWithDataById(id);
|
||||
if (userWithData == null) return null;
|
||||
|
||||
final packs = await _db.userDao.getUserPacks(id);
|
||||
final userModel = await userWithData.user.toUserModel(packs);
|
||||
|
||||
// TODO: загрузить UserDataModel если нужно
|
||||
// userModel.userData = userWithData.userData?.toUserDataModel();
|
||||
|
||||
return userModel;
|
||||
}
|
||||
|
||||
/// Создать пользователя
|
||||
Future<String> createUser(UserModel userModel) async {
|
||||
final userCompanion = userModel.toUsersCompanion();
|
||||
|
|
|
|||
Loading…
Reference in a new issue