@manyos/smileconnect-api 1.41.4 → 1.42.1
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 +9 -7
- package/conf/clients.json +6 -2
- package/conf/customFormMapping.json +30 -0
- package/conf/mapping.json +0 -34
- package/controller/customFormController.js +13 -13
- package/controller/taskController.js +3 -0
- package/controller/ticketController.js +1 -0
- package/controller/ticketWorkLogController.js +2 -0
- package/docs/openapi.json +27 -27
- package/docs/releases.md +11 -1
- package/package.json +1 -1
- package/routes/appConfigRoutes.js +102 -0
- package/routes/customFormRoutes.js +5 -5
- package/util/config.js +55 -2
- package/util/constants.js +1 -0
- package/util/mappingUtil.js +76 -1
- package/util/paramHelper.js +1 -0
- package/util/schemas/fieldMappingSchema.js +28 -1
- package/util/searchUtil.js +68 -1
- package/docs/old/getting-started.md +0 -19
- package/docs/old/index.md +0 -41
- package/docs/old/installation.md +0 -123
- package/docs/old/postinstall.md +0 -169
- package/docs/old/preinstall.md +0 -19
- package/docs/old/tags.html +0 -34
- package/docs/old/workflow.md +0 -127
package/app.js
CHANGED
|
@@ -229,6 +229,9 @@ app.get('/debug', function (req, res, next) {
|
|
|
229
229
|
|
|
230
230
|
});*/
|
|
231
231
|
|
|
232
|
+
app.use(['/v1/health', '/v1/healthcheck'], function (req, res, next) {
|
|
233
|
+
res.json({status:"ok"})
|
|
234
|
+
})
|
|
232
235
|
|
|
233
236
|
//global authentication
|
|
234
237
|
app.use(passport.authenticate('jwt', {session: false}), responseHandler.logRequest);
|
|
@@ -296,10 +299,13 @@ app.use('/v1/templates/(|incidents|problems|workorders|changes|tasks)', function
|
|
|
296
299
|
}, templateRoutes);
|
|
297
300
|
|
|
298
301
|
//formhandling
|
|
299
|
-
app.use('/v1/customForms/:
|
|
302
|
+
app.use('/v1/customForms/:formAlias', async function(req, res, next) {
|
|
303
|
+
const formAlias = req.params.formAlias
|
|
304
|
+
const formMapping = await config.getCustomFormMapping(formAlias)
|
|
300
305
|
req.formConfig = {
|
|
301
|
-
formName:
|
|
302
|
-
configName: 'custom_' +
|
|
306
|
+
formName: formMapping.formName,
|
|
307
|
+
configName: 'custom_' + formMapping.formName,
|
|
308
|
+
mapping: formMapping.mapping
|
|
303
309
|
}
|
|
304
310
|
req.parentEventBase = 'customForm'
|
|
305
311
|
next();
|
|
@@ -343,10 +349,6 @@ app.use('/v1/:requestType/:parentId/tasks', function(req, res, next) {
|
|
|
343
349
|
|
|
344
350
|
app.use(relatedObjectsController.getRelatedObjects);
|
|
345
351
|
|
|
346
|
-
app.get("/health", function (req, res) {
|
|
347
|
-
res.status(200).send();
|
|
348
|
-
});
|
|
349
|
-
|
|
350
352
|
app.use(responseHandler.eventQueueHandler);
|
|
351
353
|
|
|
352
354
|
app.use(responseHandler.logErrors);
|
package/conf/clients.json
CHANGED
|
@@ -137,7 +137,6 @@
|
|
|
137
137
|
"translateSelectionFieldsX": false
|
|
138
138
|
},
|
|
139
139
|
"custom_Sample:Enrollments": {
|
|
140
|
-
"formName": "Sample:Enrollments",
|
|
141
140
|
"basequery": "1=1",
|
|
142
141
|
"fields": [
|
|
143
142
|
"Enrollment ID",
|
|
@@ -369,7 +368,8 @@
|
|
|
369
368
|
"Direct Contact Person ID",
|
|
370
369
|
"Submit Date",
|
|
371
370
|
"Last Modified Date",
|
|
372
|
-
"Resolution"
|
|
371
|
+
"Resolution",
|
|
372
|
+
"Submitter"
|
|
373
373
|
],
|
|
374
374
|
"constants": [
|
|
375
375
|
{
|
|
@@ -395,6 +395,10 @@
|
|
|
395
395
|
{
|
|
396
396
|
"name": "Status",
|
|
397
397
|
"value": "0"
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
"name": "Submitter",
|
|
401
|
+
"value": "Horstinaut"
|
|
398
402
|
}
|
|
399
403
|
],
|
|
400
404
|
"basequery": "1=1",
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"persons": {
|
|
3
|
+
"formName": "CTM:People",
|
|
4
|
+
"mapping": {
|
|
5
|
+
"Remedy Login ID": "id",
|
|
6
|
+
"Full Name": "name"
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"enrollments": {
|
|
10
|
+
"formName": "Sample:Enrollments",
|
|
11
|
+
"mapping": {
|
|
12
|
+
"Enrollment ID": "id",
|
|
13
|
+
"Enrollee Login": "userId",
|
|
14
|
+
"Class ID": "classId",
|
|
15
|
+
"Class Title": "classTitle",
|
|
16
|
+
"Class Location": "location",
|
|
17
|
+
"Class Start Date & Time": "startDate",
|
|
18
|
+
"Class Cost": "cost",
|
|
19
|
+
"Department": "department"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"baseElement": {
|
|
23
|
+
"formName": "AST:BaseElement",
|
|
24
|
+
"mapping": {
|
|
25
|
+
"Instance Id": "id",
|
|
26
|
+
"Class Id": "class",
|
|
27
|
+
"Class Id2": "class4"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
package/conf/mapping.json
CHANGED
|
@@ -1,38 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
"custom_Sample:Enrollments": [
|
|
3
|
-
{
|
|
4
|
-
"oldName": "Enrollment ID",
|
|
5
|
-
"newName": "id"
|
|
6
|
-
},
|
|
7
|
-
{
|
|
8
|
-
"oldName": "Enrollee Login",
|
|
9
|
-
"newName": "userId"
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
"oldName": "Class ID",
|
|
13
|
-
"newName": "classId"
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"oldName": "Class Title",
|
|
17
|
-
"newName": "classTitle"
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
"oldName": "Class Location",
|
|
21
|
-
"newName": "location"
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
"oldName": "Class Start Date & Time",
|
|
25
|
-
"newName": "startDate"
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
"oldName": "Class Cost",
|
|
29
|
-
"newName": "cost"
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
"oldName": "Department",
|
|
33
|
-
"newName": "department"
|
|
34
|
-
}
|
|
35
|
-
],
|
|
36
2
|
"cmdbobject": [
|
|
37
3
|
{
|
|
38
4
|
"oldName": "Instance Id",
|
|
@@ -6,7 +6,7 @@ const CacheService = require ('../util/cache.service');
|
|
|
6
6
|
const config = require('../util/config');
|
|
7
7
|
const CONSTANTS = require('../util/constants');
|
|
8
8
|
const searchUtil = require('../util/searchUtil');
|
|
9
|
-
const {getIncludeArray,
|
|
9
|
+
const {getIncludeArray, applyCustomFormMapping} = require('../util/paramHelper');
|
|
10
10
|
const scriptController = require('./scriptController');
|
|
11
11
|
const mappingUtil = require('../util/mappingUtil');
|
|
12
12
|
|
|
@@ -31,12 +31,12 @@ async function createRecord(formConfig, clientConfig, data, globalScriptParams)
|
|
|
31
31
|
|
|
32
32
|
const requestType = formConfig.requestType;
|
|
33
33
|
|
|
34
|
-
const mapping =
|
|
34
|
+
const mapping = formConfig.mapping;
|
|
35
35
|
log.debug('mapping', mapping);
|
|
36
36
|
|
|
37
|
-
const fields =
|
|
37
|
+
const fields = clientConfig[formConfig.configName].fields
|
|
38
38
|
|
|
39
|
-
data = mappingUtil.
|
|
39
|
+
data = mappingUtil.applyCustomFormMapping2Remedy(data, mapping, clientConfig[formConfig.configName].constants, fields);
|
|
40
40
|
|
|
41
41
|
//run postScripts
|
|
42
42
|
if (scripts && scripts.postMapping) {
|
|
@@ -55,7 +55,7 @@ async function createRecord(formConfig, clientConfig, data, globalScriptParams)
|
|
|
55
55
|
log.error('Cannot create Record', resultInterfaceCreate);
|
|
56
56
|
throw({message: 'Cannot create Record', details : resultInterfaceCreate});
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
globalScriptParams.id = recordCreateId
|
|
59
59
|
//run afterExecution
|
|
60
60
|
if (scripts && scripts.afterExecution) {
|
|
61
61
|
await scriptController.runScripts(scripts.afterExecution, data, clientConfig.clientId, globalScriptParams);
|
|
@@ -84,7 +84,7 @@ function queryRecords(formConfig, clientConfig, query, mapping, customFields, cu
|
|
|
84
84
|
const key = baseQuery + fields.toString() + query + JSON.stringify(options) + includeArray;
|
|
85
85
|
log.debug('Cachekey is ', key);
|
|
86
86
|
if (mapping == null || mapping == undefined) {
|
|
87
|
-
mapping =
|
|
87
|
+
mapping = formConfig.mapping
|
|
88
88
|
}
|
|
89
89
|
log.debug('mapping', mapping);
|
|
90
90
|
|
|
@@ -124,7 +124,7 @@ async function handleRecord(formConfig, record, mapping, clientConfig, includeAr
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
mappingUtil.applyCustomFormMapping(record, mapping);
|
|
128
128
|
|
|
129
129
|
//run postScripts
|
|
130
130
|
if (scripts && scripts.postMapping) {
|
|
@@ -160,9 +160,9 @@ async function updateRecord(formConfig, clientConfig, id, recordData, globalScri
|
|
|
160
160
|
await scriptController.runScripts(scripts.preMapping, recordData, clientConfig.clientId, globalScriptParams);
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
const mapping =
|
|
163
|
+
const mapping = formConfig.mapping
|
|
164
164
|
|
|
165
|
-
recordData = mappingUtil.
|
|
165
|
+
recordData = mappingUtil.applyCustomFormMapping2Remedy(recordData, mapping, clientConfig[formConfig.configName].constants, fields);
|
|
166
166
|
|
|
167
167
|
//run postMapping
|
|
168
168
|
if (scripts && scripts.postMapping) {
|
|
@@ -180,10 +180,10 @@ async function updateRecord(formConfig, clientConfig, id, recordData, globalScri
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
function searchRecords(formConfig, clientConfig, searchString, fields, options, includeString, globalScriptParams) {
|
|
183
|
-
const mapping =
|
|
184
|
-
const mappedString = searchUtil.
|
|
185
|
-
const customFields = searchUtil.
|
|
186
|
-
options.sort = searchUtil.
|
|
183
|
+
const mapping = formConfig.mapping
|
|
184
|
+
const mappedString = searchUtil.applyCustomFormMapping(searchString, mapping);
|
|
185
|
+
const customFields = searchUtil.getCustomFormFields(clientConfig[formConfig.configName].fields, mapping, fields);
|
|
186
|
+
options.sort = searchUtil.applyCustomFormSortMapping(options.sort, mapping);
|
|
187
187
|
return queryRecords(formConfig, clientConfig, mappedString, null, customFields, options, includeString, globalScriptParams);
|
|
188
188
|
}
|
|
189
189
|
|
|
@@ -81,6 +81,8 @@ async function createTask(clientConfig, rootForm, rootRequestId, taskData, creat
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
const taskResult = await arquery.createEntry('TMS:Task', taskData, clientConfig.options)
|
|
84
|
+
const taskId = taskResult['0'];
|
|
85
|
+
globalScriptParams.id2 = taskId;
|
|
84
86
|
|
|
85
87
|
//run afterExecution
|
|
86
88
|
if (scripts && scripts.afterExecution) {
|
|
@@ -148,6 +150,7 @@ async function createWorklog(clientConfig, taskId, data, globalScriptParams) {
|
|
|
148
150
|
}
|
|
149
151
|
|
|
150
152
|
const result = await arquery.createEntry('TMS:WorkInfo', data, clientConfig.options)
|
|
153
|
+
globalScriptParams.id3 = result['0']
|
|
151
154
|
|
|
152
155
|
//run afterExecution
|
|
153
156
|
if (scripts && scripts.afterExecution) {
|
|
@@ -50,6 +50,7 @@ async function createTicket(ticketConfig, clientConfig, data, globalScriptParams
|
|
|
50
50
|
const resultInterfaceCreate = await arquery.executeARQuery(ticketConfig.forms.new, null, "'1'=\"" + ticketCreateId + "\"", ticketConfig.ticketIdField, clientConfig.options)
|
|
51
51
|
if (resultInterfaceCreate.data && Array.isArray(resultInterfaceCreate.data) && resultInterfaceCreate.data.length && resultInterfaceCreate.data[0][ticketConfig.ticketIdField]) {
|
|
52
52
|
const ticketId = resultInterfaceCreate.data[0][ticketConfig.ticketIdField];
|
|
53
|
+
globalScriptParams.id = ticketId
|
|
53
54
|
} else {
|
|
54
55
|
log.error('Cannot create Ticket', resultInterfaceCreate);
|
|
55
56
|
throw({message: 'Cannot create Ticket', details : resultInterfaceCreate});
|
|
@@ -73,6 +73,8 @@ async function createWorklog(ticketConfig, clientConfig, ticketId, data, globalS
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
const result = arquery.createEntry(ticketConfig.forms.workLog, data, clientConfig.options)
|
|
76
|
+
const worklogId = result['0'];
|
|
77
|
+
globalScriptParams.id2 = worklogId
|
|
76
78
|
|
|
77
79
|
//run afterExecution
|
|
78
80
|
if (scripts && scripts.afterExecution) {
|
package/docs/openapi.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"openapi": "3.0.2",
|
|
3
3
|
"info": {
|
|
4
4
|
"title": "SMILEconnect",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.41.4",
|
|
6
6
|
"contact": {
|
|
7
7
|
"name": "manyos technology GmbH",
|
|
8
8
|
"url": "https://manyos.it",
|
|
@@ -4838,32 +4838,6 @@
|
|
|
4838
4838
|
"id": "WLG000000000533"
|
|
4839
4839
|
}
|
|
4840
4840
|
},
|
|
4841
|
-
"WorklogNew": {
|
|
4842
|
-
"title": "Root Type for Worklog",
|
|
4843
|
-
"description": "",
|
|
4844
|
-
"required": [
|
|
4845
|
-
"summary",
|
|
4846
|
-
"text"
|
|
4847
|
-
],
|
|
4848
|
-
"type": "object",
|
|
4849
|
-
"properties": {
|
|
4850
|
-
"summary": {
|
|
4851
|
-
"type": "string"
|
|
4852
|
-
},
|
|
4853
|
-
"text": {
|
|
4854
|
-
"type": "string"
|
|
4855
|
-
},
|
|
4856
|
-
"isPublic": {
|
|
4857
|
-
"description": "Defines whether this worklog is public or only internal. Public worklogs are share with the requestor of the ticket. Internal worklogs are only visible within the support organization.\nDefaults to false (internal only).",
|
|
4858
|
-
"type": "boolean"
|
|
4859
|
-
}
|
|
4860
|
-
},
|
|
4861
|
-
"example": {
|
|
4862
|
-
"summary": "Status Change",
|
|
4863
|
-
"text": "Status Marked: Resolved by Allen",
|
|
4864
|
-
"isPublic": true
|
|
4865
|
-
}
|
|
4866
|
-
},
|
|
4867
4841
|
"WorklogResponseList": {
|
|
4868
4842
|
"description": "",
|
|
4869
4843
|
"required": [
|
|
@@ -16078,6 +16052,32 @@
|
|
|
16078
16052
|
"id": "ars101",
|
|
16079
16053
|
"code": "try {\n const result = await adapter.remedy.search(params.form, params.query, params.valueField + ',' + params.labelField);\n const data = result.data.map(item => {\n return {\n \"value\":item[params.valueField],\n \"label\":item[params.labelField],\n }\n });\n resolve(data);\n} catch (error) {\n reject(error);\n}"
|
|
16080
16054
|
}
|
|
16055
|
+
},
|
|
16056
|
+
"WorklogNew": {
|
|
16057
|
+
"title": "Root Type for Worklog",
|
|
16058
|
+
"description": "",
|
|
16059
|
+
"required": [
|
|
16060
|
+
"summary",
|
|
16061
|
+
"text"
|
|
16062
|
+
],
|
|
16063
|
+
"type": "object",
|
|
16064
|
+
"properties": {
|
|
16065
|
+
"summary": {
|
|
16066
|
+
"type": "string"
|
|
16067
|
+
},
|
|
16068
|
+
"text": {
|
|
16069
|
+
"type": "string"
|
|
16070
|
+
},
|
|
16071
|
+
"isPublic": {
|
|
16072
|
+
"description": "Deprecated - use mapping of view Access instead. Will be removed in future versions.\n\nDefines whether this worklog is public or only internal. Public worklogs are share with the requestor of the ticket. Internal worklogs are only visible within the support organization.\nDefaults to false (internal only).",
|
|
16073
|
+
"type": "boolean"
|
|
16074
|
+
}
|
|
16075
|
+
},
|
|
16076
|
+
"example": {
|
|
16077
|
+
"summary": "Status Change",
|
|
16078
|
+
"text": "Status Marked: Resolved by Allen",
|
|
16079
|
+
"isPublic": true
|
|
16080
|
+
}
|
|
16081
16081
|
}
|
|
16082
16082
|
},
|
|
16083
16083
|
"responses": {
|
package/docs/releases.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
## API
|
|
4
4
|
|
|
5
|
+
### 1.42.1 - 09.09.21
|
|
6
|
+
Fix authentication issue with health check
|
|
7
|
+
|
|
8
|
+
### 1.42.0 - 08.09.21
|
|
9
|
+
|
|
10
|
+
Add IDs to POST Actions for After Execution Scripts
|
|
11
|
+
|
|
5
12
|
### 1.41.4 - 10.08.21
|
|
6
13
|
|
|
7
14
|
Fix mapping for Ticket Worklogs
|
|
@@ -34,10 +41,13 @@ The eventmanager will check all outbound webhooks for an event. If one fails, th
|
|
|
34
41
|
|
|
35
42
|
## GUI
|
|
36
43
|
|
|
44
|
+
### 1.4.18 - 11.08.21
|
|
45
|
+
hovering on fields in mappingtable, destroys values in "new" mapping, in some situations
|
|
46
|
+
|
|
37
47
|
### 1.4.17 - 09.08.21
|
|
38
48
|
|
|
39
49
|
Multiple events caused an error in the UI.
|
|
40
50
|
|
|
41
51
|
### 1.4.16 - 02.08.21
|
|
42
52
|
|
|
43
|
-
Add Auth + Scripts to Event config
|
|
53
|
+
Add Auth + Scripts to Event config
|
package/package.json
CHANGED
|
@@ -86,6 +86,108 @@ module.exports = (function() {
|
|
|
86
86
|
}
|
|
87
87
|
});
|
|
88
88
|
|
|
89
|
+
routes.get('/mappings/customForms', isAuthorizedAdmin,
|
|
90
|
+
async function (req, res, next) {
|
|
91
|
+
setEventData(
|
|
92
|
+
req,
|
|
93
|
+
CONSTANTS.EVENT_BASE_APC,
|
|
94
|
+
CONSTANTS.EVENT_ACTION_QUERY,
|
|
95
|
+
CONSTANTS.FORM_APC_MAPPING_CUSTOMFORM
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
const fieldMapping = await config.getCustomFormMapping();
|
|
100
|
+
log.debug('get all field mappings', fieldMapping);
|
|
101
|
+
if (fieldMapping == null || fieldMapping == undefined) {
|
|
102
|
+
next('Could not load mappings');
|
|
103
|
+
} else {
|
|
104
|
+
req.result = {
|
|
105
|
+
"data": fieldMapping
|
|
106
|
+
};
|
|
107
|
+
next();
|
|
108
|
+
}
|
|
109
|
+
} catch (error) {
|
|
110
|
+
next(error);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
routes.get('/mappings/customForms/:id', isAuthorizedAdmin,
|
|
115
|
+
async function (req, res, next) {
|
|
116
|
+
const id = req.params.id
|
|
117
|
+
setEventData(
|
|
118
|
+
req,
|
|
119
|
+
CONSTANTS.EVENT_BASE_APC,
|
|
120
|
+
CONSTANTS.EVENT_ACTION_QUERY,
|
|
121
|
+
CONSTANTS.FORM_APC_MAPPING_CUSTOMFORM,
|
|
122
|
+
id
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
const fieldMapping = await config.getCustomFormMapping(id);
|
|
127
|
+
log.debug('get all field mappings', fieldMapping);
|
|
128
|
+
if (fieldMapping == null || fieldMapping == undefined) {
|
|
129
|
+
next('Could not load mappings');
|
|
130
|
+
} else {
|
|
131
|
+
req.result = {
|
|
132
|
+
"data": fieldMapping
|
|
133
|
+
};
|
|
134
|
+
next();
|
|
135
|
+
}
|
|
136
|
+
} catch (error) {
|
|
137
|
+
next(error);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
routes.put('/mappings/customForms/:id', isAuthorizedAdmin,
|
|
142
|
+
checkSchema(fieldMappingSchemas.customFormMappingItemSchema),
|
|
143
|
+
async function (req, res, next) {
|
|
144
|
+
const id = req.params.id;
|
|
145
|
+
setEventData(
|
|
146
|
+
req,
|
|
147
|
+
CONSTANTS.EVENT_BASE_APC,
|
|
148
|
+
CONSTANTS.EVENT_ACTION_MODIFY,
|
|
149
|
+
CONSTANTS.FORM_APC_MAPPING_CUSTOMFORM,
|
|
150
|
+
id,
|
|
151
|
+
req.body
|
|
152
|
+
);
|
|
153
|
+
const errors = validationResult(req);
|
|
154
|
+
if (!errors.isEmpty()) {
|
|
155
|
+
req.errorStatus = 422;
|
|
156
|
+
next(errors.array());
|
|
157
|
+
} else {
|
|
158
|
+
try {
|
|
159
|
+
const data = await config.setCustomFormMapping(req.body.data, id)
|
|
160
|
+
req.result = {
|
|
161
|
+
data
|
|
162
|
+
}
|
|
163
|
+
next();
|
|
164
|
+
} catch (error) {
|
|
165
|
+
next(error);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
routes.put('/mappings/customForms', isAuthorizedAdmin,
|
|
171
|
+
async function (req, res, next) {
|
|
172
|
+
setEventData(
|
|
173
|
+
req,
|
|
174
|
+
CONSTANTS.EVENT_BASE_APC,
|
|
175
|
+
CONSTANTS.EVENT_ACTION_MODIFY,
|
|
176
|
+
CONSTANTS.FORM_APC_MAPPING_CUSTOMFORM,
|
|
177
|
+
undefined,
|
|
178
|
+
req.body
|
|
179
|
+
);
|
|
180
|
+
try {
|
|
181
|
+
const data = await config.setCustomFormMapping(req.body.data)
|
|
182
|
+
req.result = {
|
|
183
|
+
data
|
|
184
|
+
}
|
|
185
|
+
next();
|
|
186
|
+
} catch (error) {
|
|
187
|
+
next(error);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
|
|
89
191
|
routes.put('/mappings/fields/:id', isAuthorizedAdmin,
|
|
90
192
|
checkSchema(fieldMappingSchemas.fieldMappingItemSchema),
|
|
91
193
|
function (req, res, next) {
|
|
@@ -33,7 +33,7 @@ module.exports = (function() {
|
|
|
33
33
|
options.offset = Number.parseInt(offset);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
customFormController.getRecords(req.formConfig, req.user.config, includeString, options, globalScriptParams).then(function (result) {
|
|
36
|
+
customFormController.getRecords(req.formConfig, req.user.config, includeString, options, req.globalScriptParams).then(function (result) {
|
|
37
37
|
log.debug('result', result);
|
|
38
38
|
req.result = {data:result.data};
|
|
39
39
|
next();
|
|
@@ -59,7 +59,7 @@ module.exports = (function() {
|
|
|
59
59
|
req.errorStatus = 422;
|
|
60
60
|
next(errors.array());
|
|
61
61
|
} else {
|
|
62
|
-
customFormController.createRecord(req.formConfig, req.user.config, req.body.data, globalScriptParams).then(async function (createResult) {
|
|
62
|
+
customFormController.createRecord(req.formConfig, req.user.config, req.body.data, req.globalScriptParams).then(async function (createResult) {
|
|
63
63
|
const recordId = createResult;
|
|
64
64
|
eventLog.setTicketId(req, recordId);
|
|
65
65
|
req.eventData.ticketNumber = recordId;
|
|
@@ -104,7 +104,7 @@ module.exports = (function() {
|
|
|
104
104
|
if (!valResult.isEmpty()) {
|
|
105
105
|
next(valResult.array());
|
|
106
106
|
} else {
|
|
107
|
-
customFormController.searchRecords(req.formConfig, req.user.config, req.body.searchString, req.body.fields, options, includeString, globalScriptParams).then(function (result) {
|
|
107
|
+
customFormController.searchRecords(req.formConfig, req.user.config, req.body.searchString, req.body.fields, options, includeString, req.globalScriptParams).then(function (result) {
|
|
108
108
|
log.debug('result', result);
|
|
109
109
|
req.result = {data:result.data};
|
|
110
110
|
next();
|
|
@@ -131,7 +131,7 @@ module.exports = (function() {
|
|
|
131
131
|
|
|
132
132
|
function getRecord(req, res, next, clientConfig, id, mapping, includeString) {
|
|
133
133
|
req.globalScriptParams.id = id
|
|
134
|
-
customFormController.getRecord(req.formConfig, clientConfig, id, mapping, includeString, globalScriptParams).then(function (result) {
|
|
134
|
+
customFormController.getRecord(req.formConfig, clientConfig, id, mapping, includeString, req.globalScriptParams).then(function (result) {
|
|
135
135
|
log.debug('result', result);
|
|
136
136
|
req.includeObjectsList = result.included;
|
|
137
137
|
req.result = {data:result.data || {}};
|
|
@@ -162,7 +162,7 @@ module.exports = (function() {
|
|
|
162
162
|
req.errorStatus = 422;
|
|
163
163
|
next(errors.array());
|
|
164
164
|
} else {
|
|
165
|
-
customFormController.updateRecord(req.formConfig, req.user.config, id, req.body.data, globalScriptParams)
|
|
165
|
+
customFormController.updateRecord(req.formConfig, req.user.config, id, req.body.data, req.globalScriptParams)
|
|
166
166
|
.then(async function (updateResult) {
|
|
167
167
|
getRecord(req, res, next, req.user.config, id, null, includeString);
|
|
168
168
|
}).catch(function (reason) {
|
package/util/config.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
|
+
const fsPromises = require('fs').promises;
|
|
3
|
+
|
|
2
4
|
const path = require('path');
|
|
3
5
|
const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
|
|
4
6
|
|
|
@@ -8,6 +10,8 @@ const CacheService = require ('../util/cache.service');
|
|
|
8
10
|
|
|
9
11
|
const CONSTANTS = require('./constants');
|
|
10
12
|
|
|
13
|
+
const configFileCustomFormMapping = 'conf/customFormMapping.json';
|
|
14
|
+
|
|
11
15
|
const configCache = new CacheService(process.env.CACHETTL_CONFIG || 3600); // Create a new cache service instance
|
|
12
16
|
|
|
13
17
|
const clientConfigItemTemplate = {
|
|
@@ -45,6 +49,35 @@ function getClient(client) {
|
|
|
45
49
|
});
|
|
46
50
|
}
|
|
47
51
|
|
|
52
|
+
async function getCustomFormMapping(objectType) {
|
|
53
|
+
log.debug('start to read config from file', configFileCustomFormMapping);
|
|
54
|
+
try {
|
|
55
|
+
const rawdata = await fsPromises.readFile(configFileCustomFormMapping);
|
|
56
|
+
const jsonData = JSON.parse(rawdata) || {};
|
|
57
|
+
if (objectType) {
|
|
58
|
+
return jsonData[objectType]
|
|
59
|
+
} else {
|
|
60
|
+
return jsonData
|
|
61
|
+
}
|
|
62
|
+
} catch (e) {
|
|
63
|
+
log.error('Cant read custom form Mapping')
|
|
64
|
+
}
|
|
65
|
+
return {}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function setCustomFormMapping(mapping, objectType) {
|
|
69
|
+
log.debug('start to update config from file', configFileCustomFormMapping);
|
|
70
|
+
log.debug('set mapping data', objectType, mapping);
|
|
71
|
+
let jsonData = await getCustomFormMapping()
|
|
72
|
+
if (objectType) {
|
|
73
|
+
jsonData[objectType] = mapping;
|
|
74
|
+
} else {
|
|
75
|
+
jsonData = mapping
|
|
76
|
+
}
|
|
77
|
+
await fsPromises.writeFile(configFileCustomFormMapping, JSON.stringify(jsonData, null, 2));
|
|
78
|
+
return getCustomFormMapping(objectType)
|
|
79
|
+
}
|
|
80
|
+
|
|
48
81
|
function getMapping(objectType) {
|
|
49
82
|
const configFile = 'conf/mapping.json';
|
|
50
83
|
log.debug('start to read config from file', configFile);
|
|
@@ -164,6 +197,23 @@ function checkMapping() {
|
|
|
164
197
|
log.info('check mapping done');
|
|
165
198
|
}
|
|
166
199
|
|
|
200
|
+
async function checkCustomFormMapping() {
|
|
201
|
+
log.info('check customForm mapping');
|
|
202
|
+
const mappings = await getCustomFormMapping();
|
|
203
|
+
const mappingAliases = Object.keys(mappings)
|
|
204
|
+
mappingAliases.forEach(mappingAlias => {
|
|
205
|
+
const mappingDef = mappings[mappingAlias]
|
|
206
|
+
log.debug('check', mappingDef)
|
|
207
|
+
if (!mappingDef.formName || !mappingDef.mapping) {
|
|
208
|
+
log.error('Remove wrong custom Form mapping', mappingDef)
|
|
209
|
+
delete mappings[mappingAlias]
|
|
210
|
+
}
|
|
211
|
+
})
|
|
212
|
+
// save
|
|
213
|
+
await setCustomFormMapping(mappings);
|
|
214
|
+
log.info('check customForm mapping done');
|
|
215
|
+
}
|
|
216
|
+
|
|
167
217
|
function checkClientConfig(client) {
|
|
168
218
|
const clientKeys = [
|
|
169
219
|
'cmdbobject',
|
|
@@ -236,10 +286,11 @@ function checkClientConfigs() {
|
|
|
236
286
|
log.info('check client configs done');
|
|
237
287
|
}
|
|
238
288
|
|
|
239
|
-
function checkConfig() {
|
|
289
|
+
async function checkConfig() {
|
|
240
290
|
log.info('check config');
|
|
241
291
|
checkMapping();
|
|
242
292
|
checkClientConfigs();
|
|
293
|
+
await checkCustomFormMapping();
|
|
243
294
|
log.info('check config done');
|
|
244
295
|
}
|
|
245
296
|
|
|
@@ -356,5 +407,7 @@ module.exports = {
|
|
|
356
407
|
checkConfig,
|
|
357
408
|
getForms,
|
|
358
409
|
getFields,
|
|
359
|
-
ticketConfig
|
|
410
|
+
ticketConfig,
|
|
411
|
+
getCustomFormMapping,
|
|
412
|
+
setCustomFormMapping
|
|
360
413
|
};
|
package/util/constants.js
CHANGED
|
@@ -21,6 +21,7 @@ module.exports = {
|
|
|
21
21
|
FORM_WORKORDER_TEMPLATE: "WOI:Template",
|
|
22
22
|
FORM_APC_CLIENTS: "ClientConfig",
|
|
23
23
|
FORM_APC_MAPPING_FIELDS: "MappingFields",
|
|
24
|
+
FORM_APC_MAPPING_CUSTOMFORM: "MappingCustomForm",
|
|
24
25
|
FORM_APC_WEBHOOK: "Webhooks",
|
|
25
26
|
FORM_APC_FORMS_FIELDS: "FormFields",
|
|
26
27
|
FORM_APC_FORMS: "Forms",
|