@@ -227,16 +227,20 @@ var Task = function(){
227
227
var dbTask = new TaskMdl ( { steps : steps } ) ;
228
228
steps = [ ] ;
229
229
index = 0 ;
230
+ var results = [ ] ;
230
231
231
232
return dbTask . save ( ) . then ( function ( _task ) {
232
233
_task . steps . forEach ( function ( step ) {
233
234
chain = chain . then ( function ( ) {
234
- return getResolveFunc ( step ) ( step , _task ) ;
235
+ return getResolveFunc ( step ) ( step , _task , results ) ;
235
236
} ) ;
236
237
} ) ;
237
238
238
- return chain . then ( function ( ) {
239
- return _task . remove ( ) ;
239
+ return chain . then ( function ( results ) {
240
+ return _task . remove ( )
241
+ . then ( function ( ) {
242
+ return Promise . resolve ( results ) ;
243
+ } ) ;
240
244
} ) . catch ( function ( err ) {
241
245
return Roller . rollOne ( _task ) . then ( function ( ) {
242
246
throw err ;
@@ -267,10 +271,11 @@ function getResolveFunc(step){
267
271
*
268
272
* @param update the update step
269
273
* @param task the task containing update
274
+ * @param results array of results from previous operations
270
275
*
271
276
* @returns {Promise|* }
272
277
*/
273
- function performUpdate ( update , task ) {
278
+ function performUpdate ( update , task , results ) {
274
279
var Collection = getModel ( update . name ) ;
275
280
276
281
handle$Token ( update . condition , true ) ;
@@ -280,11 +285,13 @@ function performUpdate(update, task) {
280
285
return storeOldData ( update , task )
281
286
. then ( function ( ) {
282
287
return updateState ( task , update . index , PENDING )
283
- . then ( function ( _task ) {
288
+ . then ( function ( ) {
284
289
return Collection . update ( update . condition , update . data , update . options )
285
290
. exec ( )
286
- . then ( function ( ) {
287
- return updateState ( _task , update . index , DONE ) ;
291
+ . then ( function ( result ) {
292
+ results . push ( result ) ;
293
+
294
+ return updateState ( task , update . index , DONE , results ) ;
288
295
} ) ;
289
296
} ) ;
290
297
} ) ;
@@ -296,10 +303,11 @@ function performUpdate(update, task) {
296
303
*
297
304
* @param save the save step
298
305
* @param task the task containing save
306
+ * @param results array of results from previous operations
299
307
*
300
308
* @returns {Promise|* }
301
309
*/
302
- function performSave ( save , task ) {
310
+ function performSave ( save , task , results ) {
303
311
var Collection = getModel ( save . name ) ;
304
312
var doc = new Collection ( save . data ) ;
305
313
var dataStore = [ ] ;
@@ -310,9 +318,11 @@ function performSave(save, task){
310
318
task . steps [ save . index ] . dataStore = dataStore ;
311
319
task . steps [ save . index ] . markModified ( "dataStore" ) ;
312
320
313
- return updateState ( task , save . index , PENDING ) . then ( function ( _task ) {
314
- return doc . save ( ) . then ( function ( ) {
315
- return updateState ( _task , save . index , DONE ) ;
321
+ return updateState ( task , save . index , PENDING ) . then ( function ( ) {
322
+ return doc . save ( ) . then ( function ( result ) {
323
+ results . push ( result ) ;
324
+
325
+ return updateState ( task , save . index , DONE , results ) ;
316
326
} ) ;
317
327
} ) ;
318
328
}
@@ -322,18 +332,21 @@ function performSave(save, task){
322
332
*
323
333
* @param remove the remove step
324
334
* @param task the task containing remove
335
+ * @param results array of results from previous operations
325
336
*
326
337
* @returns {Promise|* }
327
338
*/
328
- function performRemove ( remove , task ) {
339
+ function performRemove ( remove , task , results ) {
329
340
var Collection = getModel ( remove . name ) ;
330
341
331
342
handle$Token ( remove . condition , true ) ;
332
343
333
344
return storeOldData ( remove , task ) . then ( function ( ) {
334
- return updateState ( task , remove . index , PENDING ) . then ( function ( _task ) {
335
- return Collection . remove ( remove . condition ) . exec ( ) . then ( function ( ) {
336
- return updateState ( _task , remove . index , DONE ) ;
345
+ return updateState ( task , remove . index , PENDING ) . then ( function ( ) {
346
+ return Collection . remove ( remove . condition ) . exec ( ) . then ( function ( result ) {
347
+ results . push ( result ) ;
348
+
349
+ return updateState ( task , remove . index , DONE , results ) ;
337
350
} ) ;
338
351
} ) ;
339
352
} ) ;
0 commit comments