Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion src/app/modules/time-clock/services/entry.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,13 @@ describe('EntryService', () => {

it('entries are found by project id with a limit 2 by default', () => {
const projectId = 'project-id';
const startDate = (moment().subtract(1, 'months')).format();
const endDate = moment().format();

service.findEntriesByProjectId(projectId).subscribe();

const restartEntryRequest = httpMock.expectOne( `${service.baseUrl}?limit=2&project_id=${projectId}`);
const restartEntryRequest = httpMock.expectOne( `${service.baseUrl}?limit=2&project_id=${projectId}&start_date=${startDate}&end_date=${endDate}`);
expect(restartEntryRequest.request.method).toBe('GET');
});

});
15 changes: 14 additions & 1 deletion src/app/modules/time-clock/services/entry.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { environment } from './../../../../environments/environment';
import { TimeEntriesTimeRange } from '../models/time-entries-time-range';
import { DatePipe } from '@angular/common';
import { Entry } from '../../shared/models';
import * as moment from 'moment';

@Injectable({
providedIn: 'root',
Expand Down Expand Up @@ -59,7 +60,9 @@ export class EntryService {
}

findEntriesByProjectId(projectId: string): Observable<Entry[]> {
const findEntriesByProjectURL = `${this.baseUrl}?limit=2&project_id=${projectId}`;
const startDate = this.getDateLastMonth();
const endDate = this.getCurrentDate();
const findEntriesByProjectURL = `${this.baseUrl}?limit=2&project_id=${projectId}&start_date=${startDate}&end_date=${endDate}`;
return this.http.get<Entry[]>(findEntriesByProjectURL);
}

Expand All @@ -77,4 +80,14 @@ export class EntryService {
}
);
}

getDateLastMonth() {
return (moment().subtract(1, 'months')).format();
}

getCurrentDate() {
return moment().format();
}


}