@manyos/smileconnect-api 1.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/.github/workflows/nodejs.yml +26 -0
  2. package/CHANGELOG.md +75 -0
  3. package/Dockerfile +21 -0
  4. package/README.md +1 -0
  5. package/app.js +316 -0
  6. package/conf/clients.json +2491 -0
  7. package/conf/mapping.json +1048 -0
  8. package/conf/scripts/p1.js +11 -0
  9. package/conf/scripts/p2.js +1 -0
  10. package/conf/scripts/p3.js +1 -0
  11. package/conf/scripts/p4.js +2 -0
  12. package/conf/scripts/script1.js +2 -0
  13. package/conf/scripts/script2.js +2 -0
  14. package/conf/scripts/script3.js +2 -0
  15. package/controller/cmdbobjectController.js +291 -0
  16. package/controller/eventLogController.js +78 -0
  17. package/controller/orgdataController.js +440 -0
  18. package/controller/relatedObjectsController.js +194 -0
  19. package/controller/scriptController.js +213 -0
  20. package/controller/taskController.js +368 -0
  21. package/controller/templateController.js +97 -0
  22. package/controller/ticketCIRelationController.js +522 -0
  23. package/controller/ticketController.js +329 -0
  24. package/controller/ticketWorkLogController.js +195 -0
  25. package/docs/.gitattributes +48 -0
  26. package/docs/404.html +13 -0
  27. package/docs/CNAME +1 -0
  28. package/docs/Gemfile +7 -0
  29. package/docs/Gemfile.lock +249 -0
  30. package/docs/_config.yml +257 -0
  31. package/docs/_data/SocialNetworks.yml +92 -0
  32. package/docs/_data/ui-text.yml +494 -0
  33. package/docs/_includes/disqus.html +17 -0
  34. package/docs/_includes/ext-css.html +7 -0
  35. package/docs/_includes/ext-js.html +7 -0
  36. package/docs/_includes/fb-comment.html +14 -0
  37. package/docs/_includes/footer-minimal.html +16 -0
  38. package/docs/_includes/footer-scripts.html +32 -0
  39. package/docs/_includes/footer.html +51 -0
  40. package/docs/_includes/google_analytics.html +14 -0
  41. package/docs/_includes/gtag.html +11 -0
  42. package/docs/_includes/gtm_body.html +6 -0
  43. package/docs/_includes/gtm_head.html +9 -0
  44. package/docs/_includes/head.html +131 -0
  45. package/docs/_includes/header.html +76 -0
  46. package/docs/_includes/just_comments.html +4 -0
  47. package/docs/_includes/matomo.html +17 -0
  48. package/docs/_includes/nav.html +57 -0
  49. package/docs/_includes/social-share.html +42 -0
  50. package/docs/_includes/staticman-comment.html +22 -0
  51. package/docs/_includes/staticman-comments.html +81 -0
  52. package/docs/_layouts/base.html +35 -0
  53. package/docs/_layouts/default.html +9 -0
  54. package/docs/_layouts/minimal.html +26 -0
  55. package/docs/_layouts/page.html +26 -0
  56. package/docs/_layouts/post.html +82 -0
  57. package/docs/_posts/2015-02-28-test-markdown.md +77 -0
  58. package/docs/aboutme.md +18 -0
  59. package/docs/css/bootstrap-social.css +147 -0
  60. package/docs/css/bootstrap-theme.css +476 -0
  61. package/docs/css/bootstrap-theme.css.map +1 -0
  62. package/docs/css/bootstrap-theme.min.css +5 -0
  63. package/docs/css/bootstrap.css +6566 -0
  64. package/docs/css/bootstrap.css.map +1 -0
  65. package/docs/css/bootstrap.min.css +5 -0
  66. package/docs/css/main-minimal.css +13 -0
  67. package/docs/css/main.css +788 -0
  68. package/docs/css/normalize.css +427 -0
  69. package/docs/css/pygment_highlights.css +61 -0
  70. package/docs/css/staticman.css +180 -0
  71. package/docs/eventlog/events.md +65 -0
  72. package/docs/feed.xml +24 -0
  73. package/docs/general/architecture.md +10 -0
  74. package/docs/general/config.md +192 -0
  75. package/docs/general/field-management.md +119 -0
  76. package/docs/general/release-notes.md +9 -0
  77. package/docs/getting-started.md +19 -0
  78. package/docs/howto/cmdbobjects.md +339 -0
  79. package/docs/howto/incident-worklogs.md +186 -0
  80. package/docs/howto/incidents.md +244 -0
  81. package/docs/howto/sample-config.md +518 -0
  82. package/docs/howto/token.md +71 -0
  83. package/docs/howto/worklog-attachment.md +113 -0
  84. package/docs/img/404-southpark.jpg +0 -0
  85. package/docs/img/architecture.jpeg +0 -0
  86. package/docs/img/attachment-upload.png +0 -0
  87. package/docs/img/avatar-icon.png +0 -0
  88. package/docs/img/bgimage.png +0 -0
  89. package/docs/img/gb-isapi.jpg +0 -0
  90. package/docs/img/install-steps.gif +0 -0
  91. package/docs/img/workflow.png +0 -0
  92. package/docs/index.md +41 -0
  93. package/docs/installation.md +123 -0
  94. package/docs/js/bootstrap.js +2306 -0
  95. package/docs/js/bootstrap.min.js +7 -0
  96. package/docs/js/jquery-1.11.2.min.js +4 -0
  97. package/docs/js/main.js +140 -0
  98. package/docs/js/staticman.js +54 -0
  99. package/docs/openapi.json +15097 -0
  100. package/docs/postinstall.md +169 -0
  101. package/docs/preinstall.md +19 -0
  102. package/docs/spec/index.html +24 -0
  103. package/docs/staticman.yml +110 -0
  104. package/docs/tags.html +34 -0
  105. package/docs/workflow.md +127 -0
  106. package/nodemon.json +3 -0
  107. package/package.json +46 -0
  108. package/routes/appConfigRoutes.js +352 -0
  109. package/routes/ciRelationRoutes.js +38 -0
  110. package/routes/cmdbObjectRoutes.js +154 -0
  111. package/routes/organisationRoutes.js +121 -0
  112. package/routes/peopleRelationRoutes.js +38 -0
  113. package/routes/personRoutes.js +131 -0
  114. package/routes/supportgroupRoutes.js +122 -0
  115. package/routes/taskRoutes.js +306 -0
  116. package/routes/templateRoutes.js +67 -0
  117. package/routes/ticketRoutes.js +181 -0
  118. package/routes/ticketWorkLogRoutes.js +185 -0
  119. package/screwdriver.yaml +52 -0
  120. package/test/appTest.js +3 -0
  121. package/test/changeTest.js +541 -0
  122. package/test/cmdbobjectTest.js +167 -0
  123. package/test/files/logo.png +0 -0
  124. package/test/incidentTest.js +539 -0
  125. package/test/orgdataTest.js +156 -0
  126. package/test/problemTest.js +512 -0
  127. package/test/templateTest.js +80 -0
  128. package/test/testUtils.js +21 -0
  129. package/test/workorderTest.js +544 -0
  130. package/util/arquery.js +416 -0
  131. package/util/auth.js +37 -0
  132. package/util/cache.service.js +52 -0
  133. package/util/config.js +361 -0
  134. package/util/constants.js +73 -0
  135. package/util/mappingUtil.js +96 -0
  136. package/util/paramHelper.js +43 -0
  137. package/util/relationUtil.js +63 -0
  138. package/util/responsehandler.js +92 -0
  139. package/util/schemas/clientConfigSchema.js +180 -0
  140. package/util/schemas/fieldMappingSchema.js +211 -0
  141. package/util/searchUtil.js +148 -0
@@ -0,0 +1,38 @@
1
+ const path = require('path');
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
3
+ const passport = require('passport');
4
+ const {body, validationResult, oneOf} = require('express-validator/check');
5
+ const cmdbobjects = require('../controller/cmdbobjectController');
6
+ const eventLog = require('../controller/eventLogController');
7
+
8
+ module.exports = (function () {
9
+ 'use strict';
10
+ const peopleRelationRoutes = require('express').Router();
11
+
12
+ peopleRelationRoutes.get('/v1/peoplerelations/:id', passport.authenticate('jwt', {session: false}),
13
+ function (req, res, next) {
14
+ const id = req.params.id;
15
+ cmdbobjects.getPeopleRelations(req.user.config, id).then(function (data) {
16
+ eventLog.createSuccessLog(
17
+ req.user.azp,
18
+ id,
19
+ 'AST:AssetPeople',
20
+ 'CMDB_PeopleRelationQuery',
21
+ req.method + ':' + req.url,
22
+ null);
23
+ res.status(200).json({"data": myObject});
24
+ }).catch(function (reason) {
25
+ eventLog.createErrorLog(
26
+ req.user.azp,
27
+ id,
28
+ 'AST:AssetPeople',
29
+ 'CMDB_PeopleRelationQuery',
30
+ req.method + ':' + req.url,
31
+ reason,
32
+ null);
33
+ res.status(500).json(reason);
34
+ })
35
+ });
36
+
37
+ return peopleRelationRoutes;
38
+ })();
@@ -0,0 +1,131 @@
1
+ const path = require('path');
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
3
+ const passport = require('passport');
4
+ const {body, validationResult, oneOf} = require('express-validator/check');
5
+ const orgdata = require('../controller/orgdataController');
6
+ const eventLog = require('../controller/eventLogController');
7
+ const CONSTANTS = require('../util/constants');
8
+
9
+ module.exports = (function() {
10
+ 'use strict';
11
+ const personRoutes = require('express').Router();
12
+
13
+ const errorFormatter = ({location, msg, param, value, nestedErrors}) => {
14
+ // Build your resulting errors however you want! String, object, whatever - it works!
15
+ return `${location}[${param}]: ${msg}`;
16
+ };
17
+
18
+ personRoutes.get('/:id', passport.authenticate('jwt', {session: false}),
19
+ function (req, res, next) {
20
+ const id = req.params.id;
21
+ const include = req.query.include;
22
+ eventLog.setEventData(
23
+ req,
24
+ CONSTANTS.EVENT_BASE_ORG_PEOPLE,
25
+ CONSTANTS.EVENT_ACTION_QUERY,
26
+ CONSTANTS.FORM_PEOPLE,
27
+ id
28
+ );
29
+
30
+ let isLoginId = false;
31
+ const paramIsLoginId = req.query.isLoginId;
32
+ if (paramIsLoginId != null && paramIsLoginId != undefined && paramIsLoginId.toLowerCase() === 'true') {
33
+ isLoginId = true;
34
+ };
35
+ orgdata.getPerson(req.user.config, id, isLoginId, null, include).then(function (result) {
36
+ if (result === undefined || Object.keys(result).length === 0) {
37
+ req.responseStatus = 404;
38
+ req.result = {
39
+ data : {}
40
+ };
41
+ } else {
42
+ req.result = {data: result.data};
43
+ req.includeObjectsList = result.included;
44
+ }
45
+ next();
46
+ }).catch(function (reason) {
47
+ next(reason);
48
+ })
49
+ });
50
+
51
+ personRoutes.get('/', passport.authenticate('jwt', {session: false}),
52
+ function (req, res, next) {
53
+ const include = req.query.include;
54
+ eventLog.setEventData(
55
+ req,
56
+ CONSTANTS.EVENT_BASE_ORG_PEOPLE,
57
+ CONSTANTS.EVENT_ACTION_QUERY,
58
+ CONSTANTS.FORM_PEOPLE
59
+ );
60
+
61
+ const options = {};
62
+ const limit = req.query.limit;
63
+ if (limit != null && limit != undefined) {
64
+ options.limit = Number.parseInt(limit);
65
+ }
66
+
67
+ const offset = req.query.offset;
68
+ if (offset != null && offset != undefined) {
69
+ options.offset = Number.parseInt(offset);
70
+ }
71
+
72
+ let isLoginId = false;
73
+ const paramIsLoginId = req.query.isLoginId;
74
+ if (paramIsLoginId != null && paramIsLoginId != undefined && paramIsLoginId.toLowerCase() === 'true') {
75
+ isLoginId = true;
76
+ };
77
+ orgdata.getPersons(req.user.config, null, include, options).then(function (result) {
78
+ req.result = {data: result.data};
79
+ req.includeObjectsList = result.included;
80
+ next();
81
+ }).catch(function (reason) {
82
+ next(reason);
83
+ })
84
+ });
85
+
86
+ personRoutes.post('/search', passport.authenticate('jwt', {session: false}),[
87
+ body('searchString').isLength({ min: 1})
88
+ ],
89
+ function (req, res, next) {
90
+ const origData = JSON.parse(JSON.stringify(req.body));
91
+ const include = req.query.include;
92
+ eventLog.setEventData(
93
+ req,
94
+ CONSTANTS.EVENT_BASE_ORG_PEOPLE,
95
+ CONSTANTS.EVENT_ACTION_SEARCH,
96
+ CONSTANTS.FORM_PEOPLE,
97
+ null,
98
+ origData
99
+ );
100
+ const options = {};
101
+ const offset = req.body.offset;
102
+ if (offset != null && offset != undefined && Number.isInteger(offset)) {
103
+ options.offset = offset;
104
+ }
105
+ const limit = req.body.limit;
106
+ if (limit != null && limit != undefined && Number.isInteger(limit)) {
107
+ options.limit = limit;
108
+ }
109
+ // check sorting
110
+ const sort = req.body.sort;
111
+ if (sort != null && sort != undefined) {
112
+ options.sort = sort;
113
+ }
114
+ log.debug('start asset search', req.body);
115
+ const valResult = validationResult(req).formatWith(errorFormatter);
116
+ log.debug('validationResult', valResult.array());
117
+ if (!valResult.isEmpty()) {
118
+ next(valResult.array());
119
+ } else {
120
+ orgdata.searchPerson(req.user.config, req.body.searchString, req.body.fields, options, include).then(function (result) {
121
+ req.result = {"data": result.data};
122
+ req.includeObjectsList = result.included;
123
+ next();
124
+ }).catch(function (reason) {
125
+ next(reason);
126
+ });
127
+ }
128
+ });
129
+
130
+ return personRoutes;
131
+ })();
@@ -0,0 +1,122 @@
1
+ const path = require('path');
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
3
+ const passport = require('passport');
4
+ const {body, validationResult, oneOf} = require('express-validator/check');
5
+ const orgdata = require('../controller/orgdataController');
6
+ const eventLog = require('../controller/eventLogController');
7
+ const CONSTANTS = require('../util/constants');
8
+
9
+
10
+ module.exports = (function() {
11
+ 'use strict';
12
+ const supportgroupRoutes = require('express').Router();
13
+
14
+ const errorFormatter = ({location, msg, param, value, nestedErrors}) => {
15
+ // Build your resulting errors however you want! String, object, whatever - it works!
16
+ return `${location}[${param}]: ${msg}`;
17
+ };
18
+
19
+ supportgroupRoutes.get('/:id', passport.authenticate('jwt', {session: false}),
20
+ function (req, res, next) {
21
+ const id = req.params.id;
22
+ const include = req.query.include;
23
+ eventLog.setEventData(
24
+ req,
25
+ CONSTANTS.EVENT_BASE_ORG_SUPPORTGROUP,
26
+ CONSTANTS.EVENT_ACTION_QUERY,
27
+ CONSTANTS.FORM_SUPPORTGROUP,
28
+ id
29
+ );
30
+ orgdata.getSupportGroup(req.user.config, id, null, include).then(function (result) {
31
+ if (!result.data || Object.keys(result.data).length === 0) {
32
+ req.responseStatus = 404;
33
+ req.result = {
34
+ data : {}
35
+ };
36
+ } else {
37
+ req.includeObjectsList = result.included;
38
+ req.result = {data:result.data || {}};
39
+ }
40
+ next();
41
+ }).catch(function (reason) {
42
+ next(reason);
43
+ })
44
+ });
45
+
46
+ supportgroupRoutes.post('/search', [
47
+ body('searchString').isLength({ min: 1})
48
+ ],
49
+ function (req, res, next) {
50
+ const origData = JSON.parse(JSON.stringify(req.body));
51
+ const include = req.query.include;
52
+ eventLog.setEventData(
53
+ req,
54
+ CONSTANTS.EVENT_BASE_ORG_SUPPORTGROUP,
55
+ CONSTANTS.EVENT_ACTION_SEARCH,
56
+ CONSTANTS.FORM_SUPPORTGROUP,
57
+ null,
58
+ origData
59
+ );
60
+ const options = {};
61
+ const offset = req.body.offset;
62
+ if (offset != null && offset != undefined && Number.isInteger(offset)) {
63
+ options.offset = offset;
64
+ }
65
+ const limit = req.body.limit;
66
+ if (limit != null && limit != undefined && Number.isInteger(limit)) {
67
+ options.limit = limit;
68
+ }
69
+ // check sorting
70
+ const sort = req.body.sort;
71
+ if (sort != null && sort != undefined) {
72
+ options.sort = sort;
73
+ }
74
+ log.debug('start support group search', req.body);
75
+ const valResult = validationResult(req).formatWith(errorFormatter);
76
+ log.debug('validationResult', valResult.array());
77
+ if (!valResult.isEmpty()) {
78
+ next(valResult.array());
79
+ } else {
80
+ orgdata.searchSupportGroup(req.user.config, req.body.searchString, req.body.fields, options, include).then(function (result) {
81
+ req.includeObjectsList = result.included;
82
+ req.result = {data:result.data || {}};
83
+ next();
84
+ }).catch(function (reason) {
85
+ next(reason);
86
+ });
87
+ }
88
+ });
89
+
90
+ supportgroupRoutes.get('/', passport.authenticate('jwt', {session: false}),
91
+ function (req, res, next) {
92
+ const include = req.query.include;
93
+ eventLog.setEventData(
94
+ req,
95
+ CONSTANTS.EVENT_BASE_ORG_SUPPORTGROUP,
96
+ CONSTANTS.EVENT_ACTION_QUERY,
97
+ CONSTANTS.FORM_SUPPORTGROUP
98
+ );
99
+
100
+ const options = {};
101
+ const limit = req.query.limit;
102
+ if (limit != null && limit != undefined) {
103
+ options.limit = Number.parseInt(limit);
104
+ }
105
+
106
+ const offset = req.query.offset;
107
+ if (offset != null && offset != undefined) {
108
+ options.offset = Number.parseInt(offset);
109
+ }
110
+
111
+
112
+ orgdata.getSupportGroups(req.user.config, null, include, options).then(function (result) {
113
+ req.includeObjectsList = result.included;
114
+ req.result = {data:result.data || {}};
115
+ next();
116
+ }).catch(function (reason) {
117
+ next(reason);
118
+ })
119
+ });
120
+
121
+ return supportgroupRoutes;
122
+ })();
@@ -0,0 +1,306 @@
1
+ const path = require('path');
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
3
+ const {body, validationResult, oneOf} = require('express-validator/check');
4
+ const task = require('../controller/taskController');
5
+ const eventLog = require('../controller/eventLogController');
6
+ const CONSTANTS = require('../util/constants');
7
+
8
+ module.exports = (function () {
9
+ const taskRoutes = require('express').Router();
10
+
11
+ const errorFormatter = ({location, msg, param, value, nestedErrors}) => {
12
+ // Build your resulting errors however you want! String, object, whatever - it works!
13
+ return `${location}[${param}]: ${msg}`;
14
+ };
15
+
16
+ taskRoutes.get('/', async function (req, res, next) {
17
+ const id = req.parentId;
18
+ //todo customize eventbase
19
+ eventLog.setEventData(
20
+ req,
21
+ req.parentEventBase,
22
+ CONSTANTS.EVENT_ACTION_QUERY,
23
+ CONSTANTS.FORM_TASK,
24
+ id
25
+ );
26
+
27
+ const result = await task.getTasksByRootRequest(req.user.config, id, req.parentForm);
28
+ req.includeObjectsList = result.included;
29
+ req.result = {data:result.data || {}};
30
+
31
+ next();
32
+ });
33
+
34
+ taskRoutes.post('/', function (req, res, next) {
35
+ const origData = JSON.parse(JSON.stringify(req.body));
36
+ eventLog.setEventData(
37
+ req,
38
+ req.parentEventBase,
39
+ CONSTANTS.EVENT_ACTION_MODIFY,
40
+ CONSTANTS.FORM_TASK,
41
+ req.parentId,
42
+ origData
43
+ );
44
+ const errors = validationResult(req).formatWith(errorFormatter);
45
+ if (!errors.isEmpty()) {
46
+ req.errorStatus = 422;
47
+ next(errors.array());
48
+ } else {
49
+ let createTaskFlow = true;
50
+ if (req.query.createTaskFlow && req.query.createTaskFlow.toLowerCase() === 'false') {
51
+ createTaskFlow = false;
52
+ }
53
+ task.createTask(req.user.config, req.parentForm, req.parentId, req.body.data, createTaskFlow).then(async function (createResult) {
54
+ log.debug('createResult', createResult);
55
+ const resultKeys = Object.keys(createResult);
56
+ let taskResult = {};
57
+ if (resultKeys.length > 1 || Array.isArray(req.body.data)) {
58
+ taskResult = [];
59
+ let x=0;
60
+ for (x=0; x<resultKeys.length; x++) {
61
+ const taskId = createResult[resultKeys[x]];
62
+ const result = await task.getTaskByRootRequest(req.user.config, req.parentId, taskId);
63
+ taskResult.push(result.data);
64
+ }
65
+ //todo fix included objects
66
+ //req.includeObjectsList = result.included;
67
+ req.result = {data:taskResult || []};
68
+ next();
69
+ } else {
70
+ const taskId = createResult['0'];
71
+ task.getTaskByRootRequest(req.user.config, req.parentId, taskId).then(function (result) {
72
+ req.includeObjectsList = result.included;
73
+ req.result = {data:result.data || {}};
74
+ next();
75
+ }).catch(function (reason) {
76
+ next(reason);
77
+ })
78
+ }
79
+ }).catch(function (reason) {
80
+ next(reason);
81
+ });
82
+ }
83
+ });
84
+
85
+ taskRoutes.get('/:taskId', async function (req, res, next) {
86
+ const parentId = req.parentId;
87
+ const taskId = req.params.taskId;
88
+ eventLog.setEventData(
89
+ req,
90
+ req.parentEventBase,
91
+ CONSTANTS.EVENT_ACTION_QUERY,
92
+ CONSTANTS.FORM_TASK,
93
+ parentId,
94
+ null,
95
+ taskId
96
+ );
97
+
98
+ const result = await task.getTaskByRootRequest(req.user.config, parentId, taskId);
99
+ req.includeObjectsList = result.included;
100
+ req.result = {data:result.data || {}};
101
+ next();
102
+ });
103
+
104
+ taskRoutes.put('/:taskId', function (req, res, next) {
105
+ const taskId = req.params.taskId;
106
+ const origData = JSON.parse(JSON.stringify(req.body));
107
+ eventLog.setEventData(
108
+ req,
109
+ req.parentEventBase,
110
+ CONSTANTS.EVENT_ACTION_MODIFY,
111
+ CONSTANTS.FORM_TASK,
112
+ req.parentId,
113
+ origData,
114
+ taskId
115
+ );
116
+ const errors = validationResult(req).formatWith(errorFormatter);
117
+ if (!errors.isEmpty()) {
118
+ req.errorStatus = 422;
119
+ next(errors.array());
120
+ } else {
121
+ task.updateTask(req.user.config, taskId, req.body.data).then(function (updateResult) {
122
+ task.getTaskByRootRequest(req.user.config, req.parentId, taskId).then(function (result) {
123
+ req.includeObjectsList = result.included;
124
+ req.result = {data:result.data || {}};
125
+ next();
126
+ }).catch(function (reason) {
127
+ next(reason);
128
+ })
129
+ }).catch(function (reason) {
130
+ next(reason);
131
+ });
132
+ }
133
+ });
134
+
135
+ taskRoutes.get('/:taskId/worklogs', async function (req, res, next) {
136
+ const taskId = req.params.taskId;
137
+ eventLog.setEventData(
138
+ req,
139
+ req.parentEventBase,
140
+ CONSTANTS.EVENT_ACTION_QUERY,
141
+ CONSTANTS.FORM_TASK_WORKLOG,
142
+ req.parentId,
143
+ null,
144
+ taskId
145
+ );
146
+
147
+ const result = await task.getTaskWorklogs(req.user.config, taskId);
148
+ req.includeObjectsList = result.included;
149
+ req.result = {data:result.data || {}};
150
+ next();
151
+
152
+ });
153
+
154
+ taskRoutes.post('/:taskId/worklogs', [
155
+ body('data.summary').isLength({ min: 1, max: 100}),
156
+ body('data.text').isLength({ min: 1})
157
+ ], async function (req, res, next) {
158
+
159
+ const origData = JSON.parse(JSON.stringify(req.body));
160
+ const taskId = req.params.taskId;
161
+ eventLog.setEventData(
162
+ req,
163
+ req.parentEventBase,
164
+ CONSTANTS.EVENT_ACTION_CREATE,
165
+ CONSTANTS.FORM_TASK_WORKLOG,
166
+ req.parentId,
167
+ origData,
168
+ taskId
169
+ );
170
+
171
+ const errors = validationResult(req).formatWith(errorFormatter);
172
+ if (!errors.isEmpty()) {
173
+ req.errorStatus = 422;
174
+ next(errors.array());
175
+ } else {
176
+ task.createWorklog(req.user.config, taskId, req.body.data.summary, req.body.data.text)
177
+ .then(createResult => {
178
+ const worklogId = createResult['0'];
179
+ task.getTaskWorklog(req.user.config, taskId, worklogId).then(result => {
180
+ const urls = {
181
+ "attachmentUrl" : `/v1/${req.parentType}/${req.parentId}/tasks/${taskId}/worklogs/${worklogId}/attachments/1`,
182
+ "attachmentUrl2" : `/v1/${req.parentType}/${req.parentId}/tasks/${taskId}/worklogs/${worklogId}/attachments/2`,
183
+ "attachmentUrl3" : `/v1/${req.parentType}/${req.parentId}/tasks/${taskId}/worklogs/${worklogId}/attachments/3`,
184
+ "self" : `/v1/${req.parentType}/${req.parentId}/tasks/${taskId}/worklogs/${worklogId}`
185
+ };
186
+ req.includeObjectsList = result.included;
187
+ req.result = {data:result.data || {}};
188
+ req.result.urls = urls;
189
+ next();
190
+ });
191
+ log.debug('WorkLog created');
192
+ })
193
+ .catch(error => {
194
+ next(error);
195
+ });
196
+ }
197
+ });
198
+
199
+ taskRoutes.get('/:taskId/worklogs/:worklogId', async function (req, res, next) {
200
+ const taskId = req.params.taskId;
201
+ const worklogId = req.params.worklogId;
202
+ eventLog.setEventData(
203
+ req,
204
+ req.parentEventBase,
205
+ CONSTANTS.EVENT_ACTION_QUERY,
206
+ CONSTANTS.FORM_TASK_WORKLOG,
207
+ req.parentId,
208
+ null,
209
+ taskId
210
+ );
211
+
212
+ const result = await task.getTaskWorklog(req.user.config, taskId, worklogId);
213
+ const urls = {
214
+ "attachmentUrl" : `/v1/${req.parentType}/${req.parentId}/tasks/${taskId}/worklogs/${worklogId}/attachments/1`,
215
+ "attachmentUrl2" : `/v1/${req.parentType}/${req.parentId}/tasks/${taskId}/worklogs/${worklogId}/attachments/2`,
216
+ "attachmentUrl3" : `/v1/${req.parentType}/${req.parentId}/tasks/${taskId}/worklogs/${worklogId}/attachments/3`,
217
+ "self" : `/v1/${req.parentType}/${req.parentId}/tasks/${taskId}/worklogs/${worklogId}`
218
+ };
219
+ log.debug('res', urls);
220
+ req.includeObjectsList = result.included;
221
+ req.result = {data:result.data || {}};
222
+ req.result.urls = urls;
223
+ next();
224
+ });
225
+
226
+ taskRoutes.post('/:taskId/worklogs/:worklogId/attachment', function (req, res, next) {
227
+ res.redirect(307, 'attachments/1');
228
+ });
229
+
230
+ taskRoutes.post('/:taskId/worklogs/:worklogId/attachments/:attachmentId',
231
+ function (req, res, next) {
232
+ const ticketId = req.params.taskId;
233
+ const worklogId = req.params.worklogId;
234
+ const attachmentId = req.params.attachmentId;
235
+
236
+ eventLog.setEventData(
237
+ req,
238
+ req.parentEventBase,
239
+ CONSTANTS.EVENT_ACTION_CREATE,
240
+ CONSTANTS.FORM_TASK_WORKLOG,
241
+ ticketId,
242
+ null,
243
+ worklogId
244
+ );
245
+
246
+ log.debug('files', req.files);
247
+ let fileContent = null;
248
+
249
+ let file = null;
250
+ if (req.files != null && req.files.file != null) {
251
+ file = req.files.file;
252
+ }
253
+ if (file == null || file == undefined) {
254
+ if (req.body.data != null && req.body.data != undefined) {
255
+ fileContent = req.body.data;
256
+ } else {
257
+ req.errorStatus = 400;
258
+ next({errorMessage:"No file or data send"});
259
+ };
260
+ } else {
261
+ //fileContent = JSON.parse(file.data);
262
+ task.setWorklogAttachment(req.user.config, worklogId, file, attachmentId).then(
263
+ uploadResult => {
264
+ req.result = uploadResult;
265
+ next();
266
+ })
267
+ .catch(error => {
268
+ next(error);
269
+ });
270
+ }
271
+ });
272
+
273
+ taskRoutes.get('/:taskId/worklogs/:worklogId/attachment', function (req, res, next) {
274
+ res.redirect('attachments/1');
275
+ });
276
+
277
+ taskRoutes.get('/:taskId/worklogs/:worklogId/attachments/:attachmentId', function (req, res, next) {
278
+ const ticketId = req.parentId;
279
+ const worklogId = req.params.worklogId;
280
+ const attachmentId = req.params.attachmentId;
281
+
282
+ eventLog.setEventData(
283
+ req,
284
+ req.parentEventBase,
285
+ CONSTANTS.EVENT_ACTION_QUERY,
286
+ CONSTANTS.FORM_TASK_WORKLOG,
287
+ ticketId,
288
+ null,
289
+ worklogId
290
+ );
291
+
292
+ //fileContent = JSON.parse(file.data);
293
+ task.getWorklogAttachment(req.user.config, worklogId, attachmentId).then(
294
+ downloadResult => {
295
+ req.downloadResult = downloadResult;
296
+ next();
297
+ })
298
+ .catch(error => {
299
+ req.errorStatus = 404;
300
+ next(error);
301
+ });
302
+
303
+ });
304
+
305
+ return taskRoutes;
306
+ })();
@@ -0,0 +1,67 @@
1
+ const path = require('path');
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
3
+ const templateController = require('../controller/templateController');
4
+ const eventLog = require('../controller/eventLogController');
5
+ const CONSTANTS = require('../util/constants');
6
+
7
+ module.exports = (function() {
8
+ const templateRoutes = require('express').Router();
9
+
10
+ templateRoutes.get('/', function (req, res, next) {
11
+ eventLog.setEventData(
12
+ req,
13
+ req.parentEventBase,
14
+ CONSTANTS.EVENT_ACTION_QUERY,
15
+ req.ticketConfig.forms.template
16
+ );
17
+ const includeString = req.query.include;
18
+
19
+ const options = {};
20
+ const limit = req.query.limit;
21
+ if (limit != null && limit != undefined) {
22
+ options.limit = Number.parseInt(limit);
23
+ }
24
+
25
+ const offset = req.query.offset;
26
+ if (offset != null && offset != undefined) {
27
+ options.offset = Number.parseInt(offset);
28
+ }
29
+
30
+ templateController.getTemplates(req.ticketConfig, req.user.config, includeString, options).then(function (result) {
31
+ log.debug('result', result);
32
+
33
+ req.includeObjectsList = result.included;
34
+ req.result = {data:result.data};
35
+ next();
36
+ }).catch(function (reason) {
37
+ next(reason);
38
+ });
39
+ });
40
+
41
+ templateRoutes.get('/:id', function (req, res, next) {
42
+ const id = req.params.id;
43
+ const includeString = req.query.include;
44
+ eventLog.setEventData(
45
+ req,
46
+ req.parentEventBase,
47
+ CONSTANTS.EVENT_ACTION_SEARCH,
48
+ req.parentForm,
49
+ id
50
+ );
51
+
52
+ templateController.getTemplate(req.ticketConfig, req.user.config, id, null, includeString).then(function (result) {
53
+ log.debug('result', result);
54
+ req.includeObjectsList = result.included;
55
+ req.result = {data:result.data || {}};
56
+ if (!result.data) {
57
+ req.responseStatus = 404;
58
+ }
59
+ next();
60
+ }).catch(function (reason) {
61
+ next (reason);
62
+ })
63
+
64
+ });
65
+
66
+ return templateRoutes;
67
+ })();