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
fix: #336 fix automatic clock outs
  • Loading branch information
enriquezrene committed Jun 3, 2020
commit bcb92d4971c3336e90aa114331d5de6d724fbe47
2 changes: 1 addition & 1 deletion src/app/modules/time-clock/store/entry.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class DeleteEntryFail implements Action {
export class UpdateActiveEntry implements Action {
public readonly type = EntryActionTypes.UPDATE_ACTIVE_ENTRY;

constructor(public payload: NewEntry) {}
constructor(public payload) {}
}

export class UpdateActiveEntrySuccess implements Action {
Expand Down
15 changes: 7 additions & 8 deletions src/app/modules/time-clock/store/entry.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as actions from './entry.actions';

@Injectable()
export class EntryEffects {
constructor(private actions$: Actions, private entryService: EntryService, private toastrService: ToastrService) {}
constructor(private actions$: Actions, private entryService: EntryService, private toastrService: ToastrService) { }

@Effect()
loadEntriesSummary$: Observable<Action> = this.actions$.pipe(
Expand All @@ -36,17 +36,16 @@ export class EntryEffects {
map((activeEntry) => {
if (activeEntry) {
const today = new Date();
const entryStartDate = new Date (activeEntry.start_date);
const entryStartDate = new Date(activeEntry.start_date);
const isSameDay = (today.getDate() === entryStartDate.getDate()
&& today.getMonth() === entryStartDate.getMonth()
&& today.getFullYear() === entryStartDate.getFullYear());
&& today.getMonth() === entryStartDate.getMonth()
&& today.getFullYear() === entryStartDate.getFullYear());
if (isSameDay) {
return new actions.LoadActiveEntrySuccess(activeEntry);
} else {
const endDate = activeEntry.start_date;
const endDate = new Date(activeEntry.start_date);
endDate.setHours(23, 59, 59);
activeEntry.end_date = endDate.toISOString();
return new actions.UpdateActiveEntry(activeEntry);
return new actions.UpdateActiveEntry({ d: activeEntry.id, end_date: endDate.toISOString() });
}
}
}),
Expand Down Expand Up @@ -119,7 +118,7 @@ export class EntryEffects {
mergeMap((entry) =>
this.entryService.updateActiveEntry(entry).pipe(
map((entryResponse) => {
if (entryResponse.end_date) {
if (entryResponse.end_date && entry.start_date === null) {
this.toastrService.success(INFO_SAVED_SUCCESSFULLY);
}
return new actions.UpdateActiveEntrySuccess(entryResponse);
Expand Down