From c84f9f5addfb0830aa9eb732ca9ffa9674cc28b9 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 11:54:42 -0300 Subject: [PATCH] fix: process modules in license --- .../data_sources/menu_local_data_source.dart | 8 ++-- .../repositories/menu_repository_impl.dart | 2 +- .../modules/domain/entities/license.dart | 47 ++++++++++--------- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart b/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart index f88d1c55..84c0ffa8 100644 --- a/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart +++ b/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart @@ -39,7 +39,7 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource { @override Future processDisplayDefault(EnumMenuItem item, MenuEntry opt, List entries) async { - if (opt.value == 'FRE-HUB-LOGOUT') { + if (opt.key == 'FRE-HUB-LOGOUT') { await addMenuEntry(item, entries, opt.icon, opt.name, () async { await AuthenticationService.signOut(navigatorKey.currentContext!); }); @@ -67,7 +67,7 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource { break; } } catch (e) { - log('Error processing display for module ${opt.value}: $e'); + log('Error processing display for module ${opt.key}: $e'); } } @@ -78,7 +78,7 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource { final start = DateTime.tryParse(startDate); return start != null && DateTime.now().isAfter(start); } catch (e) { - log('Error processing start date for module ${opt.value}: $e'); + log('Error processing start date for module ${opt.key}: $e'); } return false; } @@ -90,7 +90,7 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource { final expiration = DateTime.tryParse(expirationDate); return expiration != null && DateTime.now().isAfter(expiration); } catch (e) { - log('Error processing expiration date for module ${opt.value}: $e'); + log('Error processing expiration date for module ${opt.key}: $e'); } return false; } diff --git a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart index d786151c..545553d3 100644 --- a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart +++ b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart @@ -21,7 +21,7 @@ class MenuRepositoryImpl implements MenuRepository { for (var opt in menuOptions) { final bool isDefault = await menuDataSource.processDisplayDefault(item, opt, entries); if (isDefault) continue; - final licenseValue = await LicenseRepositoryImpl().getLicense(opt.value); + final licenseValue = await LicenseRepositoryImpl().getLicense(opt.key); if (licenseValue != null) { final licenseMap = await stringToMap(licenseValue); final display = EnumDisplay.fromString(licenseMap['display']); diff --git a/lib/shared/components/molecules/modules/domain/entities/license.dart b/lib/shared/components/molecules/modules/domain/entities/license.dart index da762027..0ab0f4c0 100644 --- a/lib/shared/components/molecules/modules/domain/entities/license.dart +++ b/lib/shared/components/molecules/modules/domain/entities/license.dart @@ -45,7 +45,7 @@ class License { ); - static Future _processWithoutLicense(LicenseKeys key) async { + static Future _processWithoutModule(LicenseKeys key) async { switch(key) { case LicenseKeys.reservations: return await _precessWpp(); @@ -87,145 +87,146 @@ class License { } - - static Future getLicense(bool isNewVersion) async { + /// Returns a [License] object with the modules and their status. + /// @param isNewVersion: Indica que é sistema novo que possui modularização. + static Future getLicense(bool isNewVersionWithModule) async { return License([ Module( key: LicenseKeys.messages.value, - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + display: ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.liberations.value, - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + display: ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.reservations.value, - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.inactive.key, + display: await _processWithoutModule(LicenseKeys.reservations), expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.access.value, - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + display: ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.openedVisits.value, - display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, + display: isNewVersionWithModule ? ModuleStatus.active.key : ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.vehicles.value, - display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, + display: isNewVersionWithModule ? ModuleStatus.active.key : ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.residents.value, - display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, + display: isNewVersionWithModule ? ModuleStatus.active.key : ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.pets.value, - display: isNewVersion ? ModuleStatus.active.key : await _processWithoutLicense(LicenseKeys.pets), + display: await _processWithoutModule(LicenseKeys.pets), expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.orders.value, - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + display: await _processWithoutModule(LicenseKeys.orders), expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.completeSchedule.value, - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + display: ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.providerSchedule.value, - display: isNewVersion ? ModuleStatus.active.key : await _processWithoutLicense(LicenseKeys.providerSchedule), + display: await _processWithoutModule(LicenseKeys.providerSchedule), expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.deliverySchedule.value, - display: isNewVersion ? ModuleStatus.active.key : await _processWithoutLicense(LicenseKeys.deliverySchedule), + display: await _processWithoutModule(LicenseKeys.deliverySchedule), expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.fastPass.value, - display: isNewVersion ? ModuleStatus.active.key : await _processWithoutLicense(LicenseKeys.fastPass), + display: await _processWithoutModule(LicenseKeys.fastPass), expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.qrCode.value, - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + display: ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.visitors.value, - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + display: ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.property.value, - display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, + display: ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.people.value, - display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.active.key, + display: isNewVersionWithModule ? ModuleStatus.inactive.key : ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.petsHistory.value, - display: isNewVersion ? ModuleStatus.active.key : await _processWithoutLicense(LicenseKeys.petsHistory), + display: isNewVersionWithModule ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.settings.value, - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + display: ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.logout.value, - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + display: ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0,