diff --git a/lib/data/Repo/leave_repo.dart b/lib/data/Repo/leave_repo.dart index 567419a2..ccede35f 100644 --- a/lib/data/Repo/leave_repo.dart +++ b/lib/data/Repo/leave_repo.dart @@ -55,11 +55,11 @@ class LeaveRepo { _leaveService.monthlyLeaveByStartDate( year: date.year, month: date.month, - spaceId: _userStateNotifier.currentSpaceId!), + spaceId: _userStateNotifier.currentSpaceId!).distinct(), _leaveService.monthlyLeaveByEndDate( year: date.year, month: date.month, - spaceId: _userStateNotifier.currentSpaceId!), + spaceId: _userStateNotifier.currentSpaceId!).distinct(), (leavesByStartDate, leavesByEndDate) { List mergedList = leavesByStartDate; mergedList.addAll(leavesByEndDate.where((endDateLeave) => @@ -67,7 +67,7 @@ class LeaveRepo { startDateLeave.leaveId == endDateLeave.leaveId))); return mergedList; }, - ); + ).distinct(); @disposeMethod Future dispose() async { diff --git a/lib/data/services/leave_service.dart b/lib/data/services/leave_service.dart index 983193e1..51863fe5 100644 --- a/lib/data/services/leave_service.dart +++ b/lib/data/services/leave_service.dart @@ -32,6 +32,8 @@ class LeaveService { Stream> monthlyLeaveByStartDate( {required int year, required int month, required String spaceId}) => _leaveDb(spaceId: _userManager.currentSpaceId!) + .where(FireStoreConst.leaveStatus, + isEqualTo: LeaveStatus.approved.value) .where(FireStoreConst.startLeaveDate, isGreaterThanOrEqualTo: DateTime(year, month).timeStampToInt) .where(FireStoreConst.startLeaveDate, @@ -42,12 +44,17 @@ class LeaveService { Stream> monthlyLeaveByEndDate( {required int year, required int month, required String spaceId}) => _leaveDb(spaceId: spaceId) + .where(FireStoreConst.leaveStatus, + isEqualTo: LeaveStatus.approved.value) .where(FireStoreConst.endLeaveDate, isGreaterThanOrEqualTo: DateTime(year, month).timeStampToInt) .where(FireStoreConst.endLeaveDate, isLessThan: DateTime(year, month + 1).timeStampToInt) .snapshots() - .map((event) => event.docs.map((leave) => leave.data()).toList()); + .asyncMap((event) => event.docs + .map((leave) => leave.data()) + .where((leave) => leave.startDate.isBefore(DateTime(year, month))) + .toList()); Stream> userLeaveByStatus( {required String uid, diff --git a/lib/ui/shared/who_is_out_card/bloc/who_is_out_card_bloc.dart b/lib/ui/shared/who_is_out_card/bloc/who_is_out_card_bloc.dart index 9103f162..4be4a4c6 100644 --- a/lib/ui/shared/who_is_out_card/bloc/who_is_out_card_bloc.dart +++ b/lib/ui/shared/who_is_out_card/bloc/who_is_out_card_bloc.dart @@ -35,17 +35,16 @@ class WhoIsOutCardBloc extends Bloc { emit(state.copyWith(status: Status.loading)); try { return emit.forEach( - getLeaveApplicationStream( - leaveStream: _leaveRepo.leaveByMonth(state.focusDay), - membersStream: _employeeRepo.employees), - onData: (List leaveApplications) => state.copyWith( - allAbsences: leaveApplications, - status: Status.success, - selectedDayAbsences: getSelectedDateAbsences( - date: state.selectedDate, allAbsences: leaveApplications)), - onError: (error, stackTrace) => state.copyWith( - status: Status.error, error: firestoreFetchDataError), - ); + getLeaveApplicationStream( + leaveStream: _leaveRepo.leaveByMonth(state.focusDay), + membersStream: _employeeRepo.employees), + onData: (List leaveApplications) => state.copyWith( + allAbsences: leaveApplications, + status: Status.success, + selectedDayAbsences: getSelectedDateAbsences( + date: state.selectedDate, allAbsences: leaveApplications)), + onError: (error, stackTrace) => state.copyWith( + status: Status.error, error: firestoreFetchDataError)); } on Exception { emit( state.copyWith(status: Status.error, error: firestoreFetchDataError));