Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit d5d3970

Browse files
committedJul 11, 2015
Update Task.js
1 parent 6faa688 commit d5d3970

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed
 

‎modules/Task/Task.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ module.factory( 'Task', (BaseObject, $http) => {
118118
}
119119

120120
update() {
121-
return $http.put(`/api/tasks/${this.id}`, this);
121+
// wraps `this.uploading` in a promise that resolves immediately if it is `null` or waits for the promise
122+
return this.updating = $q.when(this.uploading)
123+
.then( () => $http.post(`/api/tasks/${this.id}`, this) ) // uploading callback
124+
.then( response => return Object.assign(this, response.data) ) // creating callback
125+
.finally( () => this.updating = null ); // state cleanup (doesn't affect chaining)
122126
}
123127

124128
/**
@@ -127,7 +131,8 @@ module.factory( 'Task', (BaseObject, $http) => {
127131
* @note Added to demonstrate clean ways to have 1 method wait for another method to finish
128132
*/
129133
upload(attachment) {
130-
return this.uploading = $http.post(`/api/tasks/${this.id}`, attachment)
134+
return this.uploading = $http.post(`/api/attachments`, attachment)
135+
.then( response => this.attachments = response.data )
131136
.finally( () => this.uploading = null ); // state cleanup (doesn't affect chaining)
132137
}
133138
}

0 commit comments

Comments
 (0)
This repository has been archived.