Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/app/modules/time-clock/services/entry.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { DatePipe } from '@angular/common';
import { Entry } from '../../shared/models';
import * as moment from 'moment';


export const MAX_NUMBER_OF_ENTRIES_FOR_REPORTS = 9999;

@Injectable({
providedIn: 'root',
})
Expand Down Expand Up @@ -69,7 +72,6 @@ export class EntryService {
}

loadEntriesByTimeRange(range: TimeEntriesTimeRange, userId: string[] | string ): Observable<any> {
const MAX_NUMBER_OF_ENTRIES_FOR_REPORTS = 9999;
const loadEntriesByTimeRangeURL = this.urlInProductionLegacy ? this.baseUrl : this.baseUrl + '/report/';
return this.http.get(loadEntriesByTimeRangeURL,
{
Expand Down
27 changes: 25 additions & 2 deletions src/app/modules/time-clock/store/entry.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import * as moment from 'moment';
import { ToastrModule, ToastrService } from 'ngx-toastr';
import { Observable, of, throwError } from 'rxjs';
import { TimeEntriesTimeRange } from '../models/time-entries-time-range';
import { EntryService } from '../services/entry.service';
import { EntryService, MAX_NUMBER_OF_ENTRIES_FOR_REPORTS } from '../services/entry.service';
import { INFO_SAVED_SUCCESSFULLY } from './../../shared/messages';
import { EntryActionTypes, SwitchTimeEntry, DeleteEntry, CreateEntry } from './entry.actions';
import { EntryEffects } from './entry.effects';


describe('TimeEntryActionEffects', () => {

let actions$: Observable<Action>;
Expand Down Expand Up @@ -385,7 +386,7 @@ describe('TimeEntryActionEffects', () => {
spyOn(toastrService, 'success');

effects.updateCurrentOrLastEntry$.subscribe(action => {
expect(toastrService.success).toHaveBeenCalledWith('You change the time-in successfully');
expect(toastrService.success).toHaveBeenCalledWith('You changed the time-in successfully');
expect(action.type).toEqual(EntryActionTypes.UPDATE_ENTRY_RUNNING);
});
});
Expand All @@ -399,4 +400,26 @@ describe('TimeEntryActionEffects', () => {
});
});

it('should show a warning when maximum number of entries is received', async () => {
const timeRange: TimeEntriesTimeRange = { start_date: moment(new Date()), end_date: moment(new Date()) };
const userId = '*';
const entries = [];
for (let i = 0; i < MAX_NUMBER_OF_ENTRIES_FOR_REPORTS; i++){
entries.push({...entry, id: i.toString() });
}

const serviceSpy = spyOn(service, 'loadEntriesByTimeRange');
serviceSpy.and.returnValue(of(entries));
spyOn(toastrService, 'warning');

actions$ = of({ type: EntryActionTypes.LOAD_ENTRIES_BY_TIME_RANGE, timeRange, userId });

effects.loadEntriesByTimeRange$.subscribe(action => {
expect(toastrService.warning).toHaveBeenCalledWith(
'Still loading. Limit of ' + MAX_NUMBER_OF_ENTRIES_FOR_REPORTS +
' entries reached, try filtering the request by users or date.' +
' Some information may be missing.'
);
});
});
});
11 changes: 9 additions & 2 deletions src/app/modules/time-clock/store/entry.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Action } from '@ngrx/store';
import { ToastrService } from 'ngx-toastr';
import { Observable, of } from 'rxjs';
import { catchError, map, mergeMap, switchMap } from 'rxjs/operators';
import { EntryService } from '../services/entry.service';
import { EntryService, MAX_NUMBER_OF_ENTRIES_FOR_REPORTS } from '../services/entry.service';
import * as actions from './entry.actions';
import * as moment from 'moment';

Expand Down Expand Up @@ -241,7 +241,7 @@ export class EntryEffects {
if (isStartTimeInLastEntry) {
return new actions.UpdateEntry({ id: lastEntry.id, end_date: entry.start_date });
} else {
this.toastrService.success('You change the time-in successfully');
this.toastrService.success('You changed the time-in successfully');
return new actions.UpdateEntryRunning(entry);
}
}),
Expand All @@ -260,6 +260,13 @@ export class EntryEffects {
mergeMap((action) =>
this.entryService.loadEntriesByTimeRange(action.timeRange, action.userId).pipe(
map((response) => {
if (response.length >= MAX_NUMBER_OF_ENTRIES_FOR_REPORTS){
this.toastrService.warning(
'Still loading. Limit of ' + MAX_NUMBER_OF_ENTRIES_FOR_REPORTS +
' entries reached, try filtering the request.' +
' Some information may be missing.'
);
}
return new actions.LoadEntriesByTimeRangeSuccess(response);
}),
catchError((error) => {
Expand Down