@manyos/smileconnect-api 1.58.0 → 1.59.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.
package/app.js CHANGED
@@ -328,6 +328,7 @@ app.use('/v1/customForms/:formAlias', async function(req, res, next) {
328
328
  configName: 'custom_' + formMapping.formName,
329
329
  mapping: formMapping.mapping
330
330
  }
331
+ req.globalScriptParams.formConfig = req.formConfig
331
332
  req.parentEventBase = 'customForm'
332
333
  next();
333
334
  }, customFormRoutes);
@@ -439,6 +439,9 @@ async function updateRelations(ticketConfig, userConfig, ticketId, relations) {
439
439
  relations.ticketRelations = undefined
440
440
  }
441
441
 
442
+ //Set error array
443
+ const errors = [];
444
+
442
445
  //Check CI Relations
443
446
  if (relations && relations.ciRelations && Array.isArray(relations.ciRelations)) {
444
447
  const existingRelations = await getTicketCIRelations(ticketId);
@@ -451,7 +454,11 @@ async function updateRelations(ticketConfig, userConfig, ticketId, relations) {
451
454
  const relationsExists = doesCIRelationExists(existingRelations, relation, relations.keepCIs);
452
455
  log.debug('createRelation, already exists', relation, relationsExists);
453
456
  if (!relationsExists) {
454
- await createTicketCIRelation(ticketConfig, ticketId, relation.ciId, relation.relationType);
457
+ try {
458
+ await createTicketCIRelation(ticketConfig, ticketId, relation.ciId, relation.relationType);
459
+ } catch (e) {
460
+ errors.push(e);
461
+ }
455
462
  }
456
463
  }
457
464
  }
@@ -462,7 +469,11 @@ async function updateRelations(ticketConfig, userConfig, ticketId, relations) {
462
469
  const shouldRelationsExists = doesCIRelationExists(relations.ciRelations, relation, relations.keepCIs);
463
470
  log.debug('deleteRelation, already exists', relation, shouldRelationsExists);
464
471
  if (shouldRelationsExists !== true) {
465
- await deleteTicketCIRelation(ticketConfig, ticketId, relation.ciId);
472
+ try {
473
+ await deleteTicketCIRelation(ticketConfig, ticketId, relation.ciId);
474
+ } catch (e) {
475
+ errors.push(e);
476
+ }
466
477
  }
467
478
  }
468
479
  }
@@ -504,6 +515,7 @@ async function updateRelations(ticketConfig, userConfig, ticketId, relations) {
504
515
  }
505
516
  }
506
517
  }
518
+ return errors;
507
519
  }
508
520
 
509
521
  function getTicketConfigByTicketType(ticketType) {
@@ -315,7 +315,11 @@ async function updateTicket(ticketConfig, clientConfig, id, ticketData, globalSc
315
315
  }
316
316
  //todo Abfangen wenn getTicket nichts liefert.
317
317
  const update = await arquery.updateEntry(ticketConfig.forms.regular, ticket.data.internalId, ticketData, clientConfig.options);
318
- await ticketCIRelationController.updateRelations(ticketConfig, clientConfig, id, relations);
318
+ const relationErrors = await ticketCIRelationController.updateRelations(ticketConfig, clientConfig, id, relations);
319
+ if (relationErrors && relationErrors.length > 0) {
320
+ log.error(relationErrors)
321
+ throw relationErrors;
322
+ }
319
323
  //run afterExecution
320
324
  if (scripts && scripts.afterExecution) {
321
325
  await scriptController.runScripts(scripts.afterExecution, ticketData, clientConfig.clientId, globalScriptParams);
package/docs/releases.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Release Notes
2
2
 
3
3
  ## API
4
+ ### 1.59.0 - 09.06.22
5
+ Collect all ciTicketRelationErrors and return them at the end
6
+
4
7
  ### 1.58.0 - 31.03.22
5
8
  Add uid() to scripts
6
9
  In customForms(create) make globalScripts.id changeable
package/docs/scripts.md CHANGED
@@ -119,8 +119,27 @@ Global script params are set by the application and handed over to the script. T
119
119
 
120
120
  **sourceData**: Contains the original body for PUT/POST request. This can be used scripts to access custom data that was removed during mapping.
121
121
 
122
- **user**: Contains the full configuration of the client. The attribute user.config.options.impersonateUser might be overwritten by the dynamic passed value if user.config.options.allowDynamicImpersonate ist set to true.
122
+ **user**: Contains the full configuration of the client. The attribute user.config.options.impersonateUser might be overwritten by the dynamic passed value if user.config.options.allowDynamicImpersonate ist set to true.
123
123
 
124
+ **formConfig**: Contains the configuration of the cutstom form. *Only available for custom forms*
125
+
126
+ e.g.
127
+ ```json
128
+ "formConfig": {
129
+ "formName": "AST:ComputerSystem",
130
+ "configName": "custom_AST:ComputerSystem",
131
+ "mapping": {
132
+ "Name": "name",
133
+ "DatasetId": "dataSetId",
134
+ "Asset ID+": "id",
135
+ "Reconciliation Identity": "reconId",
136
+ "Instance Id": "instanceId",
137
+ "Short Description": "shortDescription"
138
+ }
139
+ }
140
+ ```
141
+
142
+ Full example:
124
143
  ```json
125
144
  {
126
145
  "query": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manyos/smileconnect-api",
3
- "version": "1.58.0",
3
+ "version": "1.59.0",
4
4
  "description": "A proxy and abstraction layer for BMCs IT Service Management Suite",
5
5
  "main": "app.js",
6
6
  "scripts": {
@@ -79,16 +79,22 @@ module.exports = (function() {
79
79
  let fileContent = null;
80
80
 
81
81
  let file = null;
82
+
82
83
  if (req.files != null && req.files.file != null) {
83
84
  file = req.files.file;
85
+ } else if (req.body.data && req.body.data.fileName && req.body.data.fileContent && req.body.data.mimetype) {
86
+ log.debug('set file by data content - currently not implemented');
87
+ //funktioniert nicht. Wahrscheinlich ein encoding problem
88
+ file = {
89
+ name: req.body.data.fileName,
90
+ data: atob(req.body.data.fileContent),
91
+ mimetype: req.body.data.mimetype
92
+ }
84
93
  }
94
+
85
95
  if (file == null || file == undefined) {
86
- if (req.body.data != null && req.body.data != undefined) {
87
- fileContent = req.body.data;
88
- } else {
89
- req.errorStatus = 400;
90
- next({errorMessage:"No file or data send"});
91
- };
96
+ req.errorStatus = 400;
97
+ next({errorMessage:"No file or data send"});
92
98
  } else {
93
99
  //fileContent = JSON.parse(file.data);
94
100
  ticketWorkLogController.setWorklogAttachment(req.ticketConfig, req.user.config, worklogId, file, attachmentId, req.globalScriptParams).then(
@@ -52,6 +52,13 @@ function errorHandler(err, req, res, next) {
52
52
  res.status(errorStatus).json({"error": "You are not authorized for this request.", stackTrace: errorStack});
53
53
  } else if (typeof errorStack === "string") {
54
54
  res.status(errorStatus).json({"error": "Ooops. Something unexpected just happened.", "stackTrace":errorStack});
55
+ } else if (Array.isArray(err)) {
56
+ err = err.map(item => {
57
+ return {
58
+ message: item.stack
59
+ }
60
+ })
61
+ res.status(errorStatus).json({"error": err});
55
62
  } else {
56
63
  res.status(errorStatus).json({"error": err});
57
64
  }
@@ -78,7 +85,9 @@ function eventQueueHandler(req, res, next) {
78
85
  res.set('Content-disposition', 'attachment; filename=' + req.downloadResult.fileName);
79
86
  res.status(200).send(req.downloadResult.data);
80
87
  } else {
88
+ log.debug('send http repsonse', req.result)
81
89
  res.status(req.responseStatus || 200).json(req.result)
90
+ log.debug('send http done')
82
91
  }
83
92
  }).catch(error => {
84
93
  next(error);