Skip to content

Commit 5cbe799

Browse files
author
Guido Quezada
committed
TT-69 fix: refactor variables and conidtions
1 parent 2e9ab62 commit 5cbe799

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/app/modules/time-entries/pages/time-entries.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ describe('TimeEntriesComponent', () => {
234234
expect(component.canMarkEntryAsWIP).toBe(true);
235235
});
236236

237-
it('displays an error when start date of entry is > than active entry start date', async () => {
237+
it('displays an error when start date of entry is greater than active entry start date', async () => {
238238
component.activeTimeEntry = entry;
239239
const newEntry = {
240240
entry: {
@@ -254,7 +254,7 @@ describe('TimeEntriesComponent', () => {
254254
expect(injectedToastrService.error).toHaveBeenCalled();
255255
});
256256

257-
it('displays an error when end date of entry is > than active entry start date', async () => {
257+
it('displays an error when end date of entry is greater than active entry start date', async () => {
258258
component.activeTimeEntry = entry;
259259
const newEntry = {
260260
entry: {

src/app/modules/time-entries/pages/time-entries.component.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,17 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
100100
}
101101

102102
saveEntry(event: SaveEntryEvent): void {
103-
if (this.activeTimeEntry !== null && this.activeTimeEntry !== undefined) {
103+
if (this.activeTimeEntry) {
104104
const startDateAsLocalDate = new Date(event.entry.start_date);
105105
const endDateAsLocalDate = new Date(event.entry.end_date);
106106
const activeEntryAsLocalDate = new Date(this.activeTimeEntry.start_date);
107-
const isEditingActiveEntry = this.entryId === this.activeTimeEntry.id;
108-
if (!isEditingActiveEntry && (startDateAsLocalDate > activeEntryAsLocalDate || endDateAsLocalDate > activeEntryAsLocalDate)) {
109-
this.toastrService.error('You are on the clock and this entry overlaps it, try with earlier times.');
110-
} else {
107+
const isEditingEntryEqualToActiveEntry = this.entryId === this.activeTimeEntry.id;
108+
const isStartDateLowerThanActiveEntry = startDateAsLocalDate < activeEntryAsLocalDate;
109+
const isEndDateLowerThanActiveEntry = endDateAsLocalDate < activeEntryAsLocalDate;
110+
if(isEditingEntryEqualToActiveEntry && (isStartDateLowerThanActiveEntry || isEndDateLowerThanActiveEntry)){
111111
this.doSave(event);
112+
} else {
113+
this.toastrService.error('You are on the clock and this entry overlaps it, try with earlier times.');
112114
}
113115
} else {
114116
this.doSave(event);

0 commit comments

Comments
 (0)