Skip to content
Merged
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
Next Next commit
fix: update doSave function #399
  • Loading branch information
Angeluz-07 committed Jun 24, 2020
commit 1d5a8a5dc6c2791f26e1e858329743d9958dc195
31 changes: 27 additions & 4 deletions src/app/modules/time-entries/pages/time-entries.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,40 @@ export class TimeEntriesComponent implements OnInit {
}

doSave(event: SaveEntryEvent) {
event.entry.start_date = new Date(event.entry.start_date).toISOString();
if (event.entry.end_date !== null && event.entry.end_date !== undefined) {
event.entry.end_date = new Date(event.entry.end_date).toISOString();
}
if (this.entryId) {
const startDateChanged = this.entry.start_date !== event.entry.start_date;
const endDateChanged = this.entry.end_date !== event.entry.end_date;

if (startDateChanged) {
const startDate = new Date(event.entry.start_date);
Copy link
Contributor

@juanultimate juanultimate Jun 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 71, 72, 73 are the same than 89,90,91. Do not you think it would be great if we extract them to a method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your're right. I thought the same. I just didn't know the code style to include functions. I will ask for help to Rene for this and also to fix the tests. Thanks for pointing it out.

startDate.setSeconds(1, 0);
event.entry.start_date = startDate.toISOString();
}

if (endDateChanged) {
if (event.entry.end_date !== null && event.entry.end_date !== undefined) {
const endDate = new Date(event.entry.end_date);
endDate.setSeconds(0, 0);
event.entry.end_date = endDate.toISOString();
}
}

event.entry.id = this.entryId;
this.store.dispatch(new entryActions.UpdateEntry(event.entry));
if (event.shouldRestartEntry) {
this.store.dispatch(new entryActions.RestartEntry(event.entry));
}
} else {
const startDate = new Date(event.entry.start_date);
startDate.setSeconds(1, 0);
event.entry.start_date = startDate.toISOString();

if (event.entry.end_date !== null && event.entry.end_date !== undefined) {
const endDate = new Date(event.entry.end_date);
endDate.setSeconds(0, 0);
event.entry.end_date = endDate.toISOString();
}

this.store.dispatch(new entryActions.CreateEntry(event.entry));
}
}
Expand Down