Skip to content

Commit

Permalink
Show all approved leaves
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-pratik-k committed Jul 27, 2023
1 parent 415f237 commit 3373d10
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
6 changes: 3 additions & 3 deletions lib/data/Repo/leave_repo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ 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<Leave> mergedList = leavesByStartDate;
mergedList.addAll(leavesByEndDate.where((endDateLeave) =>
!leavesByEndDate.any((startDateLeave) =>
startDateLeave.leaveId == endDateLeave.leaveId)));
return mergedList;
},
);
).distinct();

@disposeMethod
Future<void> dispose() async {
Expand Down
9 changes: 8 additions & 1 deletion lib/data/services/leave_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class LeaveService {
Stream<List<Leave>> 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,
Expand All @@ -42,12 +44,17 @@ class LeaveService {
Stream<List<Leave>> 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<List<Leave>> userLeaveByStatus(
{required String uid,
Expand Down
21 changes: 10 additions & 11 deletions lib/ui/shared/who_is_out_card/bloc/who_is_out_card_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,16 @@ class WhoIsOutCardBloc extends Bloc<WhoIsOutEvent, WhoIsOutCardState> {
emit(state.copyWith(status: Status.loading));
try {
return emit.forEach(
getLeaveApplicationStream(
leaveStream: _leaveRepo.leaveByMonth(state.focusDay),
membersStream: _employeeRepo.employees),
onData: (List<LeaveApplication> 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<LeaveApplication> 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));
Expand Down

0 comments on commit 3373d10

Please sign in to comment.