@@ -38,39 +38,7 @@ var fileIo = require('_pr/lib/utils/fileio');
3838module . exports . setRoutes = function ( app , sessionVerification ) {
3939 app . all ( '/tasks/*' , sessionVerification ) ;
4040
41- app . get ( '/tasks/serviceDelivery' , function ( req , res ) {
42- var serviceDeliveryCheck = false ;
43- if ( req . query . serviceDeliveryCheck &&
44- ( req . query . serviceDeliveryCheck === 'true' || req . query . serviceDeliveryCheck === true ) ) {
45- serviceDeliveryCheck = true ;
46- }
47- Tasks . getTasksServiceDeliveryCheck ( serviceDeliveryCheck , function ( err , tasks ) {
48- if ( err ) {
49- res . status ( 500 ) . send ( {
50- code : 500 ,
51- errMessage : "Task fetch failed."
52- } ) ;
53- return ;
54- }
55- res . status ( 200 ) . send ( tasks ) ;
56- } ) ;
57- } ) ;
58-
59- app . delete ( '/tasks/serviceDelivery/:taskId' , function ( req , res ) {
60- Tasks . removeServiceDeliveryTask ( req . params . taskId , function ( err , data ) {
61- if ( err ) {
62- logger . error ( "Failed to delete service delivery Task" , err ) ;
63- res . send ( 500 , errorResponses . db . error ) ;
64- return ;
65- }
66- res . send ( 200 , {
67- message : "deleted"
68- } ) ;
69- } ) ;
70- } ) ;
71-
7241 app . get ( '/tasks/history/list/all' , function ( req , res ) {
73- logger . debug ( "------------------ " , JSON . stringify ( TaskHistory ) ) ;
7442 TaskHistory . listHistory ( function ( err , tHistories ) {
7543 if ( err ) {
7644 res . status ( 500 ) . send ( errorResponses . db . error ) ;
@@ -126,7 +94,22 @@ module.exports.setRoutes = function(app, sessionVerification) {
12694 } ) ;
12795 } ) ;
12896
97+ app . delete ( '/tasks/serviceDelivery/:taskId' , function ( req , res ) {
98+ Tasks . removeServiceDeliveryTask ( req . params . taskId , function ( err , data ) {
99+ if ( err ) {
100+ logger . error ( "Failed to delete service delivery Task" , err ) ;
101+ res . send ( 500 , errorResponses . db . error ) ;
102+ return ;
103+ }
104+ res . send ( 200 , {
105+ message : "deleted"
106+ } ) ;
107+ } ) ;
108+ } ) ;
109+
110+
129111 app . post ( '/tasks/:taskId/run' , function ( req , res ) {
112+
130113 var taskId = req . params . taskId ;
131114 var user = req . session . user . cn ;
132115 var hostProtocol = req . protocol + '://' + req . get ( 'host' ) ;
@@ -136,43 +119,11 @@ module.exports.setRoutes = function(app, sessionVerification) {
136119 var cookbookAttributes = req . body . cookbookAttributes ;
137120 var botTagServer = req . body . tagServer ;
138121
139-
140- logger . debug ( 'reqbody ======>' , JSON . stringify ( req . body ) ) ;
141-
142-
143-
144- /*Tasks.getTaskById(req.params.taskId, function(err, task) {
145-
146- if (err) {
147- logger.error(err);
148- res.status(500).send(errorResponses.db.error);
149- return;
150- }
151- var blueprintIds = [];
152- if (task.blueprintIds && task.blueprintIds.length) {
153- blueprintIds = task.blueprintIds
154- }
155- task.execute(req.session.user.cn, req.protocol + '://' + req.get('host'), choiceParam, nexusData, blueprintIds, task.envId, function(err, taskRes, historyData) {
156- if (err) {
157- logger.error(err);
158- res.status(500).send(err);
159- return;
160- }
161- if (historyData) {
162- taskRes.historyId = historyData.id;
163- }
164- logger.debug("taskRes::::: ", JSON.stringify(taskRes));
165- res.send(taskRes);
166- });
167- });
168- */
169-
170122 var paramOptions = {
171123 cookbookAttributes : cookbookAttributes ,
172124 scriptParams : scriptParams
173125 } ;
174126
175- // encrypting script bot params if any
176127 if ( paramOptions . scriptParams && paramOptions . scriptParams . length ) {
177128 var cryptoConfig = appConfig . cryptoSettings ;
178129 var cryptography = new Cryptography ( cryptoConfig . algorithm , cryptoConfig . password ) ;
@@ -185,8 +136,6 @@ module.exports.setRoutes = function(app, sessionVerification) {
185136 paramOptions . scriptParams = encryptedParams ;
186137 }
187138
188-
189-
190139 taskService . executeTask ( taskId , user , hostProtocol , choiceParam , appData , paramOptions , botTagServer , function ( err , historyData ) {
191140 if ( err === 404 ) {
192141 res . status ( 404 ) . send ( "Task not found." ) ;
@@ -524,27 +473,44 @@ module.exports.setRoutes = function(app, sessionVerification) {
524473
525474 function getTaskList ( req , res , next ) {
526475 var reqData = { } ;
527- async . waterfall (
528- [
529-
530- function ( next ) {
531- apiUtil . paginationRequest ( req . query , 'tasks' , next ) ;
532- } ,
533- function ( paginationReq , next ) {
534- reqData = paginationReq ;
535- Tasks . listTasks ( paginationReq , next ) ;
536- } ,
537- function ( tasks , next ) {
538- apiUtil . paginationResponse ( tasks , reqData , next ) ;
476+ if ( req . query . page ) {
477+ async . waterfall (
478+ [
479+ function ( next ) {
480+ apiUtil . paginationRequest ( req . query , 'tasks' , next ) ;
481+ } ,
482+ function ( paginationReq , next ) {
483+ paginationReq [ 'searchColumns' ] = [ 'name' , 'orgName' , 'bgName' , 'projectName' , 'envName' ] ;
484+ reqData = paginationReq ;
485+ apiUtil . databaseUtil ( paginationReq , next ) ;
486+ } ,
487+ function ( queryObj , next ) {
488+ Tasks . listTasks ( queryObj , next ) ;
489+ } ,
490+ function ( tasks , next ) {
491+ apiUtil . paginationResponse ( tasks , reqData , next ) ;
492+ }
493+ ] ,
494+ function ( err , results ) {
495+ if ( err ) {
496+ return res . status ( 500 ) . send ( err ) ;
497+ } else {
498+ return res . status ( 200 ) . send ( results ) ;
499+ }
500+ } ) ;
501+ } else {
502+ var queryObj = {
503+ serviceDeliveryCheck : req . query . serviceDeliveryCheck === "true" ? true :false ,
504+ actionStatus :req . query . actionStatus
505+ }
506+ taskService . getAllServiceDeliveryTask ( queryObj , function ( err , data ) {
507+ if ( err ) {
508+ return res . status ( 500 ) . send ( err ) ;
509+ } else {
510+ return res . status ( 200 ) . send ( data ) ;
539511 }
540-
541- ] ,
542- function ( err , results ) {
543- if ( err )
544- next ( err ) ;
545- else
546- return res . status ( 200 ) . send ( results ) ;
547- } ) ;
512+ } )
513+ }
548514 }
549515
550516 app . post ( '/tasks/:taskId/update' , function ( req , res ) {
0 commit comments