Skip to content

Instantly share code, notes, and snippets.

@gavilanch
Last active June 17, 2019 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gavilanch/11f143d6fd739adfb6d8a266541a37d4 to your computer and use it in GitHub Desktop.
Save gavilanch/11f143d6fd739adfb6d8a266541a37d4 to your computer and use it in GitHub Desktop.
saveTodo() {
if (this.todoForm.invalid) {
return;
}
if (this.createMode) {
let todo: Todo = this.todoForm.value;
todo.lastModifiedDate = new Date();
todo.createdDate = new Date();
this.todoService.saveTodo(todo)
.then(response => this.handleSuccessfulSaveTodo(response, todo))
.catch(err => console.error(err));
} else {
let todo: TodoViewModel = this.todoForm.value;
todo.id = this.todo.id;
todo.lastModifiedDate = new Date();
this.todoService.editTodo(todo)
.then(() => this.handleSuccessfulEditTodo(todo))
.catch(err => console.error(err));
}
}
handleSuccessfulSaveTodo(response: DocumentReference, todo: Todo) {
this.activeModal.dismiss({ todo: todo, id: response.id, createMode: true });
}
handleSuccessfulEditTodo(todo: TodoViewModel) {
this.activeModal.dismiss({ todo: todo, id: todo.id, createMode: false });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment