Skip to content

Commit

Permalink
Delete support
Browse files Browse the repository at this point in the history
  • Loading branch information
wtrocki authored and danielpassos committed Dec 4, 2018
1 parent ce8eab2 commit 25d3d31
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
20 changes: 11 additions & 9 deletions src/app/pages/home/home.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,20 @@ export class HomePage implements OnInit {
}

deleteItem(item) {
console.log('Delete item');
// TODO
this.itemService.deleteItem(item).subscribe(result => {
console.log('Result from query', result);
this.loading = result.loading;
this.errors = result.errors;
if (result.data) {
this.items = this.items.filter((data: any) => {
return !data.id === result.data.deleteTask;
});
}
});
}

subscribe() {
console.log('Subscribe');
// TODO
}

loadMore(item) {
console.log('Load more items');
// TODO
}

}

10 changes: 5 additions & 5 deletions src/app/pages/update-item/update-item.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ export class UpdateItemPage implements OnInit {
description: new FormControl(this.item.description, Validators.required),
});
}
)
);
}

goBack(){
goBack() {
this.router.navigate(['/home']);
}

updateItem(value){
let newValues = {
updateItem(value) {
const newValues = {
id: this.item.id,
title: value.title,
description: value.description
}
};
this.itemService.updateItem(newValues);
this.goBack();
}
Expand Down
7 changes: 1 addition & 6 deletions src/app/services/graphql.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ export const GET_TASKS = gql`

export const DELETE_TASK = gql`
mutation deleteTask($id: ID!){
deleteTask(id: $id){
id
title
description
version
}
deleteTask(id: $id)
}
`;

Expand Down
6 changes: 5 additions & 1 deletion src/app/services/item.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { GET_TASKS , UPDATE_TASK } from './graphql.queries';
import { GET_TASKS, UPDATE_TASK, DELETE_TASK } from './graphql.queries';
import { Apollo } from 'apollo-angular';


Expand Down Expand Up @@ -36,4 +36,8 @@ export class ItemService {
updateItem(newValues) {
return this.apollo.mutate<Task>({ mutation: UPDATE_TASK, variables: newValues });
}

deleteItem(item) {
return this.apollo.mutate<Task>({ mutation: DELETE_TASK, variables: { id: item.id } });
}
}

0 comments on commit 25d3d31

Please sign in to comment.