diff --git a/apps/mobile/packages/features/staff/profile_sections/compliance/tax_forms/lib/src/data/repositories/tax_forms_repository_impl.dart b/apps/mobile/packages/features/staff/profile_sections/compliance/tax_forms/lib/src/data/repositories/tax_forms_repository_impl.dart index be9a1cc0..c834f02f 100644 --- a/apps/mobile/packages/features/staff/profile_sections/compliance/tax_forms/lib/src/data/repositories/tax_forms_repository_impl.dart +++ b/apps/mobile/packages/features/staff/profile_sections/compliance/tax_forms/lib/src/data/repositories/tax_forms_repository_impl.dart @@ -1,7 +1,5 @@ import 'dart:async'; -import 'package:firebase_auth/firebase_auth.dart' as auth; -import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_data_connect/firebase_data_connect.dart'; import 'package:krow_data_connect/krow_data_connect.dart' as dc; import 'package:krow_domain/krow_domain.dart'; @@ -10,45 +8,21 @@ import '../../domain/repositories/tax_forms_repository.dart'; import '../mappers/tax_form_mapper.dart'; class TaxFormsRepositoryImpl - with dc.DataErrorHandler implements TaxFormsRepository { - TaxFormsRepositoryImpl({ - required this.firebaseAuth, - required this.dataConnect, - }); + TaxFormsRepositoryImpl() : _service = dc.DataConnectService.instance; - final auth.FirebaseAuth firebaseAuth; - final dc.ExampleConnector dataConnect; - - /// Helper to get the logged-in staff ID. - String _getStaffId() { - final auth.User? user = firebaseAuth.currentUser; - if (user == null) { - throw const NotAuthenticatedException( - technicalMessage: 'Firebase User is null', - ); - } - - final String? staffId = dc.StaffSessionStore.instance.session?.staff?.id; - if (staffId == null || staffId.isEmpty) { - throw const StaffProfileNotFoundException( - technicalMessage: 'Staff ID missing in SessionStore', - ); - } - return staffId; - } + final dc.DataConnectService _service; @override Future> getTaxForms() async { - return executeProtected(() async { - final String staffId = _getStaffId(); - final QueryResult - result = await dataConnect + return _service.run(() async { + final String staffId = await _service.getStaffId(); + final response = await _service.connector .getTaxFormsByStaffId(staffId: staffId) .execute(); final List forms = - result.data.taxForms.map(TaxFormMapper.fromDataConnect).toList(); + response.data.taxForms.map(TaxFormMapper.fromDataConnect).toList(); // Check if required forms exist, create if not. final Set typesPresent = @@ -65,11 +39,9 @@ class TaxFormsRepositoryImpl } if (createdNew) { - final QueryResult< - dc.GetTaxFormsByStaffIdData, - dc.GetTaxFormsByStaffIdVariables> result2 = - await dataConnect.getTaxFormsByStaffId(staffId: staffId).execute(); - return result2.data.taxForms + final response2 = + await _service.connector.getTaxFormsByStaffId(staffId: staffId).execute(); + return response2.data.taxForms .map(TaxFormMapper.fromDataConnect) .toList(); } @@ -79,7 +51,7 @@ class TaxFormsRepositoryImpl } Future _createInitialForm(String staffId, TaxFormType type) async { - await dataConnect + await _service.connector .createTaxForm( staffId: staffId, formType: @@ -95,10 +67,10 @@ class TaxFormsRepositoryImpl @override Future updateI9Form(I9TaxForm form) async { - return executeProtected(() async { + return _service.run(() async { final Map data = form.formData; final dc.UpdateTaxFormVariablesBuilder builder = - dataConnect.updateTaxForm(id: form.id); + _service.connector.updateTaxForm(id: form.id); _mapCommonFields(builder, data); _mapI9Fields(builder, data); await builder.execute(); @@ -107,10 +79,10 @@ class TaxFormsRepositoryImpl @override Future submitI9Form(I9TaxForm form) async { - return executeProtected(() async { + return _service.run(() async { final Map data = form.formData; final dc.UpdateTaxFormVariablesBuilder builder = - dataConnect.updateTaxForm(id: form.id); + _service.connector.updateTaxForm(id: form.id); _mapCommonFields(builder, data); _mapI9Fields(builder, data); await builder.status(dc.TaxFormStatus.SUBMITTED).execute(); @@ -119,10 +91,10 @@ class TaxFormsRepositoryImpl @override Future updateW4Form(W4TaxForm form) async { - return executeProtected(() async { + return _service.run(() async { final Map data = form.formData; final dc.UpdateTaxFormVariablesBuilder builder = - dataConnect.updateTaxForm(id: form.id); + _service.connector.updateTaxForm(id: form.id); _mapCommonFields(builder, data); _mapW4Fields(builder, data); await builder.execute(); @@ -131,10 +103,10 @@ class TaxFormsRepositoryImpl @override Future submitW4Form(W4TaxForm form) async { - return executeProtected(() async { + return _service.run(() async { final Map data = form.formData; final dc.UpdateTaxFormVariablesBuilder builder = - dataConnect.updateTaxForm(id: form.id); + _service.connector.updateTaxForm(id: form.id); _mapCommonFields(builder, data); _mapW4Fields(builder, data); await builder.status(dc.TaxFormStatus.SUBMITTED).execute(); diff --git a/apps/mobile/packages/features/staff/profile_sections/compliance/tax_forms/lib/src/staff_tax_forms_module.dart b/apps/mobile/packages/features/staff/profile_sections/compliance/tax_forms/lib/src/staff_tax_forms_module.dart index 95fdd71e..c26c007f 100644 --- a/apps/mobile/packages/features/staff/profile_sections/compliance/tax_forms/lib/src/staff_tax_forms_module.dart +++ b/apps/mobile/packages/features/staff/profile_sections/compliance/tax_forms/lib/src/staff_tax_forms_module.dart @@ -1,7 +1,5 @@ -import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter_modular/flutter_modular.dart'; import 'package:krow_core/core.dart'; -import 'package:krow_data_connect/krow_data_connect.dart'; import 'package:krow_domain/krow_domain.dart'; import 'data/repositories/tax_forms_repository_impl.dart'; import 'domain/repositories/tax_forms_repository.dart'; @@ -18,12 +16,7 @@ import 'presentation/pages/tax_forms_page.dart'; class StaffTaxFormsModule extends Module { @override void binds(Injector i) { - i.addLazySingleton( - () => TaxFormsRepositoryImpl( - firebaseAuth: FirebaseAuth.instance, - dataConnect: ExampleConnector.instance, - ), - ); + i.addLazySingleton(TaxFormsRepositoryImpl.new); // Use Cases i.addLazySingleton(GetTaxFormsUseCase.new);