feat: Implement use cases for personal info, emergency contacts, experience, and tax forms completion
This commit is contained in:
@@ -21,4 +21,8 @@ export 'src/services/mixins/data_error_handler.dart';
|
|||||||
// Export Staff Connector repositories and use cases
|
// Export Staff Connector repositories and use cases
|
||||||
export 'src/connectors/staff/domain/repositories/staff_connector_repository.dart';
|
export 'src/connectors/staff/domain/repositories/staff_connector_repository.dart';
|
||||||
export 'src/connectors/staff/domain/usecases/get_profile_completion_usecase.dart';
|
export 'src/connectors/staff/domain/usecases/get_profile_completion_usecase.dart';
|
||||||
|
export 'src/connectors/staff/domain/usecases/get_personal_info_completion_usecase.dart';
|
||||||
|
export 'src/connectors/staff/domain/usecases/get_emergency_contacts_completion_usecase.dart';
|
||||||
|
export 'src/connectors/staff/domain/usecases/get_experience_completion_usecase.dart';
|
||||||
|
export 'src/connectors/staff/domain/usecases/get_tax_forms_completion_usecase.dart';
|
||||||
export 'src/connectors/staff/data/repositories/staff_connector_repository_impl.dart';
|
export 'src/connectors/staff/data/repositories/staff_connector_repository_impl.dart';
|
||||||
@@ -36,8 +36,84 @@ class StaffConnectorRepositoryImpl implements StaffConnectorRepository {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<bool> getPersonalInfoCompletion() async {
|
||||||
|
return _service.run(() async {
|
||||||
|
final String staffId = await _service.getStaffId();
|
||||||
|
|
||||||
|
final QueryResult<GetStaffPersonalInfoCompletionData,
|
||||||
|
GetStaffPersonalInfoCompletionVariables> response =
|
||||||
|
await _service.connector
|
||||||
|
.getStaffPersonalInfoCompletion(id: staffId)
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
final GetStaffPersonalInfoCompletionStaff? staff = response.data.staff;
|
||||||
|
|
||||||
|
return _isPersonalInfoComplete(staff);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<bool> getEmergencyContactsCompletion() async {
|
||||||
|
return _service.run(() async {
|
||||||
|
final String staffId = await _service.getStaffId();
|
||||||
|
|
||||||
|
final QueryResult<GetStaffEmergencyProfileCompletionData,
|
||||||
|
GetStaffEmergencyProfileCompletionVariables> response =
|
||||||
|
await _service.connector
|
||||||
|
.getStaffEmergencyProfileCompletion(id: staffId)
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
return response.data.emergencyContacts.isNotEmpty;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<bool> getExperienceCompletion() async {
|
||||||
|
return _service.run(() async {
|
||||||
|
final String staffId = await _service.getStaffId();
|
||||||
|
|
||||||
|
final QueryResult<GetStaffExperienceProfileCompletionData,
|
||||||
|
GetStaffExperienceProfileCompletionVariables> response =
|
||||||
|
await _service.connector
|
||||||
|
.getStaffExperienceProfileCompletion(id: staffId)
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
final GetStaffExperienceProfileCompletionStaff? staff =
|
||||||
|
response.data.staff;
|
||||||
|
|
||||||
|
return _hasExperience(staff);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<bool> getTaxFormsCompletion() async {
|
||||||
|
return _service.run(() async {
|
||||||
|
final String staffId = await _service.getStaffId();
|
||||||
|
|
||||||
|
final QueryResult<GetStaffTaxFormsProfileCompletionData,
|
||||||
|
GetStaffTaxFormsProfileCompletionVariables> response =
|
||||||
|
await _service.connector
|
||||||
|
.getStaffTaxFormsProfileCompletion(id: staffId)
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
return response.data.taxForms.isNotEmpty;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Checks if personal info is complete.
|
||||||
|
bool _isPersonalInfoComplete(GetStaffPersonalInfoCompletionStaff? staff) {
|
||||||
|
if (staff == null) return false;
|
||||||
|
final String? fullName = staff.fullName;
|
||||||
|
final String? email = staff.email;
|
||||||
|
final String? phone = staff.phone;
|
||||||
|
return (fullName?.trim().isNotEmpty ?? false) &&
|
||||||
|
(email?.trim().isNotEmpty ?? false) &&
|
||||||
|
(phone?.trim().isNotEmpty ?? false);
|
||||||
|
}
|
||||||
|
|
||||||
/// Checks if staff has experience data (skills or industries).
|
/// Checks if staff has experience data (skills or industries).
|
||||||
bool _hasExperience(GetStaffProfileCompletionStaff? staff) {
|
bool _hasExperience(GetStaffExperienceProfileCompletionStaff? staff) {
|
||||||
if (staff == null) return false;
|
if (staff == null) return false;
|
||||||
final dynamic skills = staff.skills;
|
final dynamic skills = staff.skills;
|
||||||
final dynamic industries = staff.industries;
|
final dynamic industries = staff.industries;
|
||||||
@@ -51,9 +127,14 @@ class StaffConnectorRepositoryImpl implements StaffConnectorRepository {
|
|||||||
List<GetStaffProfileCompletionEmergencyContacts> emergencyContacts,
|
List<GetStaffProfileCompletionEmergencyContacts> emergencyContacts,
|
||||||
List<GetStaffProfileCompletionTaxForms> taxForms,
|
List<GetStaffProfileCompletionTaxForms> taxForms,
|
||||||
) {
|
) {
|
||||||
return staff != null &&
|
if (staff == null) return false;
|
||||||
emergencyContacts.isNotEmpty &&
|
final dynamic skills = staff.skills;
|
||||||
|
final dynamic industries = staff.industries;
|
||||||
|
final bool hasExperience =
|
||||||
|
(skills is List && skills.isNotEmpty) ||
|
||||||
|
(industries is List && industries.isNotEmpty);
|
||||||
|
return emergencyContacts.isNotEmpty &&
|
||||||
taxForms.isNotEmpty &&
|
taxForms.isNotEmpty &&
|
||||||
_hasExperience(staff);
|
hasExperience;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,4 +10,24 @@ abstract interface class StaffConnectorRepository {
|
|||||||
///
|
///
|
||||||
/// Throws an exception if the query fails.
|
/// Throws an exception if the query fails.
|
||||||
Future<bool> getProfileCompletion();
|
Future<bool> getProfileCompletion();
|
||||||
|
|
||||||
|
/// Fetches personal information completion status.
|
||||||
|
///
|
||||||
|
/// Returns true if personal info (name, email, phone, locations) is complete.
|
||||||
|
Future<bool> getPersonalInfoCompletion();
|
||||||
|
|
||||||
|
/// Fetches emergency contacts completion status.
|
||||||
|
///
|
||||||
|
/// Returns true if at least one emergency contact exists.
|
||||||
|
Future<bool> getEmergencyContactsCompletion();
|
||||||
|
|
||||||
|
/// Fetches experience completion status.
|
||||||
|
///
|
||||||
|
/// Returns true if staff has industries or skills defined.
|
||||||
|
Future<bool> getExperienceCompletion();
|
||||||
|
|
||||||
|
/// Fetches tax forms completion status.
|
||||||
|
///
|
||||||
|
/// Returns true if at least one tax form exists.
|
||||||
|
Future<bool> getTaxFormsCompletion();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import 'package:krow_core/core.dart';
|
||||||
|
|
||||||
|
import '../repositories/staff_connector_repository.dart';
|
||||||
|
|
||||||
|
/// Use case for retrieving emergency contacts completion status.
|
||||||
|
///
|
||||||
|
/// This use case encapsulates the business logic for determining whether
|
||||||
|
/// a staff member has at least one emergency contact registered.
|
||||||
|
/// It delegates to the repository for data access.
|
||||||
|
class GetEmergencyContactsCompletionUseCase extends NoInputUseCase<bool> {
|
||||||
|
/// Creates a [GetEmergencyContactsCompletionUseCase].
|
||||||
|
///
|
||||||
|
/// Requires a [StaffConnectorRepository] for data access.
|
||||||
|
GetEmergencyContactsCompletionUseCase({
|
||||||
|
required StaffConnectorRepository repository,
|
||||||
|
}) : _repository = repository;
|
||||||
|
|
||||||
|
final StaffConnectorRepository _repository;
|
||||||
|
|
||||||
|
/// Executes the use case to get emergency contacts completion status.
|
||||||
|
///
|
||||||
|
/// Returns true if emergency contacts are registered, false otherwise.
|
||||||
|
///
|
||||||
|
/// Throws an exception if the operation fails.
|
||||||
|
@override
|
||||||
|
Future<bool> call() => _repository.getEmergencyContactsCompletion();
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import 'package:krow_core/core.dart';
|
||||||
|
|
||||||
|
import '../repositories/staff_connector_repository.dart';
|
||||||
|
|
||||||
|
/// Use case for retrieving experience completion status.
|
||||||
|
///
|
||||||
|
/// This use case encapsulates the business logic for determining whether
|
||||||
|
/// a staff member has experience data (skills or industries) defined.
|
||||||
|
/// It delegates to the repository for data access.
|
||||||
|
class GetExperienceCompletionUseCase extends NoInputUseCase<bool> {
|
||||||
|
/// Creates a [GetExperienceCompletionUseCase].
|
||||||
|
///
|
||||||
|
/// Requires a [StaffConnectorRepository] for data access.
|
||||||
|
GetExperienceCompletionUseCase({
|
||||||
|
required StaffConnectorRepository repository,
|
||||||
|
}) : _repository = repository;
|
||||||
|
|
||||||
|
final StaffConnectorRepository _repository;
|
||||||
|
|
||||||
|
/// Executes the use case to get experience completion status.
|
||||||
|
///
|
||||||
|
/// Returns true if experience data is defined, false otherwise.
|
||||||
|
///
|
||||||
|
/// Throws an exception if the operation fails.
|
||||||
|
@override
|
||||||
|
Future<bool> call() => _repository.getExperienceCompletion();
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import 'package:krow_core/core.dart';
|
||||||
|
|
||||||
|
import '../repositories/staff_connector_repository.dart';
|
||||||
|
|
||||||
|
/// Use case for retrieving personal information completion status.
|
||||||
|
///
|
||||||
|
/// This use case encapsulates the business logic for determining whether
|
||||||
|
/// a staff member's personal information is complete (name, email, phone).
|
||||||
|
/// It delegates to the repository for data access.
|
||||||
|
class GetPersonalInfoCompletionUseCase extends NoInputUseCase<bool> {
|
||||||
|
/// Creates a [GetPersonalInfoCompletionUseCase].
|
||||||
|
///
|
||||||
|
/// Requires a [StaffConnectorRepository] for data access.
|
||||||
|
GetPersonalInfoCompletionUseCase({
|
||||||
|
required StaffConnectorRepository repository,
|
||||||
|
}) : _repository = repository;
|
||||||
|
|
||||||
|
final StaffConnectorRepository _repository;
|
||||||
|
|
||||||
|
/// Executes the use case to get personal info completion status.
|
||||||
|
///
|
||||||
|
/// Returns true if personal information is complete, false otherwise.
|
||||||
|
///
|
||||||
|
/// Throws an exception if the operation fails.
|
||||||
|
@override
|
||||||
|
Future<bool> call() => _repository.getPersonalInfoCompletion();
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import 'package:krow_core/core.dart';
|
||||||
|
|
||||||
import '../repositories/staff_connector_repository.dart';
|
import '../repositories/staff_connector_repository.dart';
|
||||||
|
|
||||||
/// Use case for retrieving staff profile completion status.
|
/// Use case for retrieving staff profile completion status.
|
||||||
@@ -5,7 +7,7 @@ import '../repositories/staff_connector_repository.dart';
|
|||||||
/// This use case encapsulates the business logic for determining whether
|
/// This use case encapsulates the business logic for determining whether
|
||||||
/// a staff member's profile is complete. It delegates to the repository
|
/// a staff member's profile is complete. It delegates to the repository
|
||||||
/// for data access.
|
/// for data access.
|
||||||
class GetProfileCompletionUseCase {
|
class GetProfileCompletionUseCase extends NoInputUseCase<bool> {
|
||||||
/// Creates a [GetProfileCompletionUseCase].
|
/// Creates a [GetProfileCompletionUseCase].
|
||||||
///
|
///
|
||||||
/// Requires a [StaffConnectorRepository] for data access.
|
/// Requires a [StaffConnectorRepository] for data access.
|
||||||
@@ -20,5 +22,6 @@ class GetProfileCompletionUseCase {
|
|||||||
/// Returns true if the profile is complete, false otherwise.
|
/// Returns true if the profile is complete, false otherwise.
|
||||||
///
|
///
|
||||||
/// Throws an exception if the operation fails.
|
/// Throws an exception if the operation fails.
|
||||||
|
@override
|
||||||
Future<bool> call() => _repository.getProfileCompletion();
|
Future<bool> call() => _repository.getProfileCompletion();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import 'package:krow_core/core.dart';
|
||||||
|
|
||||||
|
import '../repositories/staff_connector_repository.dart';
|
||||||
|
|
||||||
|
/// Use case for retrieving tax forms completion status.
|
||||||
|
///
|
||||||
|
/// This use case encapsulates the business logic for determining whether
|
||||||
|
/// a staff member has at least one tax form submitted.
|
||||||
|
/// It delegates to the repository for data access.
|
||||||
|
class GetTaxFormsCompletionUseCase extends NoInputUseCase<bool> {
|
||||||
|
/// Creates a [GetTaxFormsCompletionUseCase].
|
||||||
|
///
|
||||||
|
/// Requires a [StaffConnectorRepository] for data access.
|
||||||
|
GetTaxFormsCompletionUseCase({
|
||||||
|
required StaffConnectorRepository repository,
|
||||||
|
}) : _repository = repository;
|
||||||
|
|
||||||
|
final StaffConnectorRepository _repository;
|
||||||
|
|
||||||
|
/// Executes the use case to get tax forms completion status.
|
||||||
|
///
|
||||||
|
/// Returns true if tax forms are submitted, false otherwise.
|
||||||
|
///
|
||||||
|
/// Throws an exception if the operation fails.
|
||||||
|
@override
|
||||||
|
Future<bool> call() => _repository.getTaxFormsCompletion();
|
||||||
|
}
|
||||||
@@ -13,8 +13,9 @@ dependencies:
|
|||||||
sdk: flutter
|
sdk: flutter
|
||||||
krow_domain:
|
krow_domain:
|
||||||
path: ../domain
|
path: ../domain
|
||||||
|
krow_core:
|
||||||
|
path: ../core
|
||||||
flutter_modular: ^6.3.0
|
flutter_modular: ^6.3.0
|
||||||
firebase_data_connect: ^0.2.2+2
|
firebase_data_connect: ^0.2.2+2
|
||||||
firebase_core: ^4.4.0
|
firebase_core: ^4.4.0
|
||||||
firebase_auth: ^6.1.4
|
firebase_auth: ^6.1.4
|
||||||
krow_core: ^0.0.1
|
|
||||||
|
|||||||
Reference in New Issue
Block a user