feat: Implement attire options, documents, and certificates completion use cases in staff profile
This commit is contained in:
@@ -24,6 +24,9 @@ export 'src/connectors/staff/domain/usecases/get_personal_info_completion_usecas
|
||||
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/domain/usecases/get_attire_options_completion_usecase.dart';
|
||||
export 'src/connectors/staff/domain/usecases/get_staff_documents_completion_usecase.dart';
|
||||
export 'src/connectors/staff/domain/usecases/get_staff_certificates_completion_usecase.dart';
|
||||
export 'src/connectors/staff/domain/usecases/get_staff_profile_usecase.dart';
|
||||
export 'src/connectors/staff/domain/usecases/sign_out_staff_usecase.dart';
|
||||
export 'src/connectors/staff/data/repositories/staff_connector_repository_impl.dart';
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:firebase_data_connect/firebase_data_connect.dart';
|
||||
import 'package:krow_core/core.dart';
|
||||
import 'package:krow_data_connect/krow_data_connect.dart' as dc;
|
||||
import 'package:krow_domain/krow_domain.dart' as domain;
|
||||
|
||||
import '../../domain/repositories/staff_connector_repository.dart';
|
||||
|
||||
/// Implementation of [StaffConnectorRepository].
|
||||
@@ -122,6 +123,125 @@ class StaffConnectorRepositoryImpl implements StaffConnectorRepository {
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool?> getAttireOptionsCompletion() async {
|
||||
return _service.run(() async {
|
||||
final String staffId = await _service.getStaffId();
|
||||
|
||||
final List<QueryResult<Object, Object?>> results =
|
||||
await Future.wait<QueryResult<Object, Object?>>(
|
||||
<Future<QueryResult<Object, Object?>>>[
|
||||
_service.connector.listAttireOptions().execute(),
|
||||
_service.connector.getStaffAttire(staffId: staffId).execute(),
|
||||
],
|
||||
);
|
||||
|
||||
final QueryResult<dc.ListAttireOptionsData, void> optionsRes =
|
||||
results[0] as QueryResult<dc.ListAttireOptionsData, void>;
|
||||
final QueryResult<dc.GetStaffAttireData, dc.GetStaffAttireVariables>
|
||||
staffAttireRes =
|
||||
results[1]
|
||||
as QueryResult<dc.GetStaffAttireData, dc.GetStaffAttireVariables>;
|
||||
|
||||
final List<dc.ListAttireOptionsAttireOptions> attireOptions =
|
||||
optionsRes.data.attireOptions;
|
||||
final List<dc.GetStaffAttireStaffAttires> staffAttire =
|
||||
staffAttireRes.data.staffAttires;
|
||||
|
||||
// Get only mandatory attire options
|
||||
final List<dc.ListAttireOptionsAttireOptions> mandatoryOptions =
|
||||
attireOptions
|
||||
.where((dc.ListAttireOptionsAttireOptions opt) =>
|
||||
opt.isMandatory ?? false)
|
||||
.toList();
|
||||
|
||||
// Return null if no mandatory attire options
|
||||
if (mandatoryOptions.isEmpty) return null;
|
||||
|
||||
// Return true only if all mandatory attire items are verified
|
||||
return mandatoryOptions.every(
|
||||
(dc.ListAttireOptionsAttireOptions mandatoryOpt) {
|
||||
final dc.GetStaffAttireStaffAttires? currentAttire = staffAttire
|
||||
.where(
|
||||
(dc.GetStaffAttireStaffAttires a) =>
|
||||
a.attireOptionId == mandatoryOpt.id,
|
||||
)
|
||||
.firstOrNull;
|
||||
|
||||
if (currentAttire == null) return false; // Not uploaded
|
||||
if (currentAttire.verificationStatus is dc.Unknown) return false;
|
||||
final dc.AttireVerificationStatus status =
|
||||
(currentAttire.verificationStatus
|
||||
as dc.Known<dc.AttireVerificationStatus>)
|
||||
.value;
|
||||
return status == dc.AttireVerificationStatus.APPROVED;
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool?> getStaffDocumentsCompletion() async {
|
||||
return _service.run(() async {
|
||||
final String staffId = await _service.getStaffId();
|
||||
|
||||
final QueryResult<
|
||||
dc.ListStaffDocumentsByStaffIdData,
|
||||
dc.ListStaffDocumentsByStaffIdVariables
|
||||
>
|
||||
response = await _service.connector
|
||||
.listStaffDocumentsByStaffId(staffId: staffId)
|
||||
.execute();
|
||||
|
||||
final List<dc.ListStaffDocumentsByStaffIdStaffDocuments> staffDocs =
|
||||
response.data.staffDocuments;
|
||||
|
||||
// Return null if no documents
|
||||
if (staffDocs.isEmpty) return null;
|
||||
|
||||
// Return true only if all documents are verified
|
||||
return staffDocs.every(
|
||||
(dc.ListStaffDocumentsByStaffIdStaffDocuments doc) {
|
||||
if (doc.status is dc.Unknown) return false;
|
||||
final dc.DocumentStatus status =
|
||||
(doc.status as dc.Known<dc.DocumentStatus>).value;
|
||||
return status == dc.DocumentStatus.VERIFIED;
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool?> getStaffCertificatesCompletion() async {
|
||||
return _service.run(() async {
|
||||
final String staffId = await _service.getStaffId();
|
||||
|
||||
final QueryResult<
|
||||
dc.ListCertificatesByStaffIdData,
|
||||
dc.ListCertificatesByStaffIdVariables
|
||||
>
|
||||
response = await _service.connector
|
||||
.listCertificatesByStaffId(staffId: staffId)
|
||||
.execute();
|
||||
|
||||
final List<dc.ListCertificatesByStaffIdCertificates> certificates =
|
||||
response.data.certificates;
|
||||
|
||||
// Return false if no certificates
|
||||
if (certificates.isEmpty) return null;
|
||||
|
||||
// Return true only if all certificates are fully validated
|
||||
return certificates.every(
|
||||
(dc.ListCertificatesByStaffIdCertificates cert) {
|
||||
if (cert.validationStatus is dc.Unknown) return false;
|
||||
final dc.ValidationStatus status =
|
||||
(cert.validationStatus as dc.Known<dc.ValidationStatus>).value;
|
||||
return status == dc.ValidationStatus.APPROVED;
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/// Checks if personal info is complete.
|
||||
bool _isPersonalInfoComplete(dc.GetStaffPersonalInfoCompletionStaff? staff) {
|
||||
if (staff == null) return false;
|
||||
@@ -208,8 +328,8 @@ class StaffConnectorRepositoryImpl implements StaffConnectorRepository {
|
||||
return response.data.benefitsDatas.map((
|
||||
dc.ListBenefitsDataByStaffIdBenefitsDatas e,
|
||||
) {
|
||||
final total = e.vendorBenefitPlan.total?.toDouble() ?? 0.0;
|
||||
final remaining = e.current.toDouble();
|
||||
final double total = e.vendorBenefitPlan.total?.toDouble() ?? 0.0;
|
||||
final double remaining = e.current.toDouble();
|
||||
return domain.Benefit(
|
||||
title: e.vendorBenefitPlan.title,
|
||||
entitlementHours: total,
|
||||
|
||||
@@ -33,6 +33,21 @@ abstract interface class StaffConnectorRepository {
|
||||
/// Returns true if at least one tax form exists.
|
||||
Future<bool> getTaxFormsCompletion();
|
||||
|
||||
/// Fetches attire options completion status.
|
||||
///
|
||||
/// Returns true if all mandatory attire options are verified.
|
||||
Future<bool?> getAttireOptionsCompletion();
|
||||
|
||||
/// Fetches documents completion status.
|
||||
///
|
||||
/// Returns true if all mandatory documents are verified.
|
||||
Future<bool?> getStaffDocumentsCompletion();
|
||||
|
||||
/// Fetches certificates completion status.
|
||||
///
|
||||
/// Returns true if all certificates are validated.
|
||||
Future<bool?> getStaffCertificatesCompletion();
|
||||
|
||||
/// Fetches the full staff profile for the current authenticated user.
|
||||
///
|
||||
/// Returns a [Staff] entity containing all profile information.
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import 'package:krow_core/core.dart';
|
||||
|
||||
import '../repositories/staff_connector_repository.dart';
|
||||
|
||||
/// Use case for retrieving attire options completion status.
|
||||
///
|
||||
/// This use case encapsulates the business logic for determining whether
|
||||
/// a staff member has fully uploaded and verified all mandatory attire options.
|
||||
/// It delegates to the repository for data access.
|
||||
class GetAttireOptionsCompletionUseCase extends NoInputUseCase<bool?> {
|
||||
/// Creates a [GetAttireOptionsCompletionUseCase].
|
||||
///
|
||||
/// Requires a [StaffConnectorRepository] for data access.
|
||||
GetAttireOptionsCompletionUseCase({
|
||||
required StaffConnectorRepository repository,
|
||||
}) : _repository = repository;
|
||||
|
||||
final StaffConnectorRepository _repository;
|
||||
|
||||
/// Executes the use case to get attire options completion status.
|
||||
///
|
||||
/// Returns true if all mandatory attire options are verified, false otherwise.
|
||||
///
|
||||
/// Throws an exception if the operation fails.
|
||||
@override
|
||||
Future<bool?> call() => _repository.getAttireOptionsCompletion();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import 'package:krow_core/core.dart';
|
||||
|
||||
import '../repositories/staff_connector_repository.dart';
|
||||
|
||||
/// Use case for retrieving certificates completion status.
|
||||
///
|
||||
/// This use case encapsulates the business logic for determining whether
|
||||
/// a staff member has fully validated all certificates.
|
||||
/// It delegates to the repository for data access.
|
||||
class GetStaffCertificatesCompletionUseCase extends NoInputUseCase<bool?> {
|
||||
/// Creates a [GetStaffCertificatesCompletionUseCase].
|
||||
///
|
||||
/// Requires a [StaffConnectorRepository] for data access.
|
||||
GetStaffCertificatesCompletionUseCase({
|
||||
required StaffConnectorRepository repository,
|
||||
}) : _repository = repository;
|
||||
|
||||
final StaffConnectorRepository _repository;
|
||||
|
||||
/// Executes the use case to get certificates completion status.
|
||||
///
|
||||
/// Returns true if all certificates are validated, false otherwise.
|
||||
///
|
||||
/// Throws an exception if the operation fails.
|
||||
@override
|
||||
Future<bool?> call() => _repository.getStaffCertificatesCompletion();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import 'package:krow_core/core.dart';
|
||||
|
||||
import '../repositories/staff_connector_repository.dart';
|
||||
|
||||
/// Use case for retrieving documents completion status.
|
||||
///
|
||||
/// This use case encapsulates the business logic for determining whether
|
||||
/// a staff member has fully uploaded and verified all mandatory documents.
|
||||
/// It delegates to the repository for data access.
|
||||
class GetStaffDocumentsCompletionUseCase extends NoInputUseCase<bool?> {
|
||||
/// Creates a [GetStaffDocumentsCompletionUseCase].
|
||||
///
|
||||
/// Requires a [StaffConnectorRepository] for data access.
|
||||
GetStaffDocumentsCompletionUseCase({
|
||||
required StaffConnectorRepository repository,
|
||||
}) : _repository = repository;
|
||||
|
||||
final StaffConnectorRepository _repository;
|
||||
|
||||
/// Executes the use case to get documents completion status.
|
||||
///
|
||||
/// Returns true if all mandatory documents are verified, false otherwise.
|
||||
///
|
||||
/// Throws an exception if the operation fails.
|
||||
@override
|
||||
Future<bool?> call() => _repository.getStaffDocumentsCompletion();
|
||||
}
|
||||
Reference in New Issue
Block a user