Skip to content

Commit 210d2dd

Browse files
fix: TT-168 Add the parameters startDate and endDate in the path (#644)
* fix: TT-168 Add the parameters startDate and endDate in the path used by the findEntriesProjectId method of the EntryService service * fix: TT-168 Remove a unnecessary lines
1 parent 118e0d1 commit 210d2dd

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/app/modules/time-clock/services/entry.service.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,13 @@ describe('EntryService', () => {
143143

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

147149
service.findEntriesByProjectId(projectId).subscribe();
148150

149-
const restartEntryRequest = httpMock.expectOne( `${service.baseUrl}?limit=2&project_id=${projectId}`);
151+
const restartEntryRequest = httpMock.expectOne( `${service.baseUrl}?limit=2&project_id=${projectId}&start_date=${startDate}&end_date=${endDate}`);
150152
expect(restartEntryRequest.request.method).toBe('GET');
151153
});
154+
152155
});

src/app/modules/time-clock/services/entry.service.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { environment } from './../../../../environments/environment';
77
import { TimeEntriesTimeRange } from '../models/time-entries-time-range';
88
import { DatePipe } from '@angular/common';
99
import { Entry } from '../../shared/models';
10+
import * as moment from 'moment';
1011

1112
@Injectable({
1213
providedIn: 'root',
@@ -59,7 +60,9 @@ export class EntryService {
5960
}
6061

6162
findEntriesByProjectId(projectId: string): Observable<Entry[]> {
62-
const findEntriesByProjectURL = `${this.baseUrl}?limit=2&project_id=${projectId}`;
63+
const startDate = this.getDateLastMonth();
64+
const endDate = this.getCurrentDate();
65+
const findEntriesByProjectURL = `${this.baseUrl}?limit=2&project_id=${projectId}&start_date=${startDate}&end_date=${endDate}`;
6366
return this.http.get<Entry[]>(findEntriesByProjectURL);
6467
}
6568

@@ -77,4 +80,12 @@ export class EntryService {
7780
}
7881
);
7982
}
83+
84+
getDateLastMonth() {
85+
return (moment().subtract(1, 'months')).format();
86+
}
87+
88+
getCurrentDate() {
89+
return moment().format();
90+
}
8091
}

0 commit comments

Comments
 (0)