added svcapi ui and camunda code
[it/otf.git] / otf-frontend / server / src / feathers / hooks / agendaJobPopulate.js
1 /*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
2 #                                                                              #\r
3 #   Licensed under the Apache License, Version 2.0 (the "License");            #\r
4 #   you may not use this file except in compliance with the License.           #\r
5 #   You may obtain a copy of the License at                                    #\r
6 #                                                                              #\r
7 #       http://www.apache.org/licenses/LICENSE-2.0                             #\r
8 #                                                                              #\r
9 #   Unless required by applicable law or agreed to in writing, software        #\r
10 #   distributed under the License is distributed on an "AS IS" BASIS,          #\r
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
12 #   See the License for the specific language governing permissions and        #\r
13 #   limitations under the License.                                             #\r
14 ##############################################################################*/\r
15 \r
16 \r
17 module.exports = function () {\r
18         return async context => {\r
19                 if (context.result.data && context.result.limit >= 0 ) {\r
20                         for (let i = 0; i < context.result.data.length; i++) {\r
21                                 await context.app.services[context.app.get('base-path') + 'test-instances']\r
22                                         .get(context.result.data[i].data.testSchedule._testInstanceId, context.params)\r
23                                         .then(result => {\r
24                                                 context.result.data[i].testInstanceName = result.testInstanceName;\r
25                                         })\r
26                                         .catch(err => {\r
27                                                 console.log(err);\r
28                                         });\r
29                         }\r
30                 } else if(context.result.limit) {\r
31                         await context.app.services[context.app.get('base-path') + 'test-instances']\r
32                                 .get(context.result.data.data.testSchedule._testInstanceId, context.params)\r
33                                 .then(result => {\r
34                                         context.result.data.testInstanceName = result.testInstanceName;\r
35                                 })\r
36                                 .catch(err => {\r
37                                         console.log(err);\r
38                                 });\r
39                 }else if (context.result.length) {\r
40                         for (let i = 0; i < context.result.length; i++) {\r
41                                 await context.app.services[context.app.get('base-path') + 'test-instances']\r
42                                         .get(context.result[i].data.testSchedule._testInstanceId, context.params)\r
43                                         .then(result => {\r
44                                                 context.result[i].testInstanceName = result.testInstanceName;\r
45                                         })\r
46                                         .catch(err => {\r
47                                                 console.log(err);\r
48                                         });\r
49                         }\r
50                 } else if(context.result.data) {\r
51                         await context.app.services[context.app.get('base-path') + 'test-instances']\r
52                                 .get(context.result.data.testSchedule._testInstanceId, context.params)\r
53                                 .then(result => {\r
54                                         context.result.testInstanceName = result.testInstanceName;\r
55                                 })\r
56                                 .catch(err => {\r
57                                         console.log(err);\r
58                                 });\r
59                 }\r
60                 return context;\r
61         };\r
62 };\r