@manyos/smileconnect-api 1.49.2 → 1.50.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/controller/customFormController.js +25 -3
- package/docs/releases.md +4 -1
- package/package.json +1 -1
- package/test/customFormTest.js +111 -0
|
@@ -12,6 +12,15 @@ const mappingUtil = require('../util/mappingUtil');
|
|
|
12
12
|
|
|
13
13
|
const ticketCache = new CacheService(process.env.CACHETTL_TICKETS || 1); // Create a new cache service instance
|
|
14
14
|
|
|
15
|
+
function getIdField(formConfig) {
|
|
16
|
+
const mapping = formConfig.mapping
|
|
17
|
+
const idField = Object.keys(mapping).find(key => mapping[key] === 'id');
|
|
18
|
+
if (!idField) {
|
|
19
|
+
return '1'
|
|
20
|
+
}
|
|
21
|
+
return idField
|
|
22
|
+
}
|
|
23
|
+
|
|
15
24
|
function getRecords(formConfig, clientConfig, includeString, customOptions, globalScriptParams) {
|
|
16
25
|
let query = '1=1';
|
|
17
26
|
return queryRecords(formConfig, clientConfig, query, null, null, customOptions, includeString, globalScriptParams);
|
|
@@ -141,8 +150,9 @@ async function handleRecord(formConfig, record, mapping, clientConfig, includeAr
|
|
|
141
150
|
}
|
|
142
151
|
|
|
143
152
|
async function getRecord(formConfig, clientConfig, id, mapping, includeString, globalScriptParams) {
|
|
144
|
-
const
|
|
145
|
-
const
|
|
153
|
+
const idField = getIdField(formConfig)
|
|
154
|
+
const query = `'${idField}'=\"${id}\"`;
|
|
155
|
+
const returnValue = await queryRecords(formConfig, clientConfig, query, mapping, null, {limit:1}, includeString, globalScriptParams);
|
|
146
156
|
const record = returnValue.data[0];
|
|
147
157
|
return {data: record};
|
|
148
158
|
}
|
|
@@ -169,7 +179,9 @@ async function updateRecord(formConfig, clientConfig, id, recordData, globalScri
|
|
|
169
179
|
await scriptController.runScripts(scripts.postMapping, recordData, clientConfig.clientId, globalScriptParams);
|
|
170
180
|
}
|
|
171
181
|
|
|
172
|
-
const
|
|
182
|
+
const internalId = await getInternalId(formConfig, clientConfig, id)
|
|
183
|
+
|
|
184
|
+
const update = await arquery.updateEntry(formConfig.formName, internalId, recordData);
|
|
173
185
|
|
|
174
186
|
//run afterExecution
|
|
175
187
|
if (scripts && scripts.afterExecution) {
|
|
@@ -179,6 +191,16 @@ async function updateRecord(formConfig, clientConfig, id, recordData, globalScri
|
|
|
179
191
|
return update;
|
|
180
192
|
}
|
|
181
193
|
|
|
194
|
+
async function getInternalId(formConfig, clientConfig, id) {
|
|
195
|
+
const idField = getIdField(formConfig)
|
|
196
|
+
const query = `'${idField}'=\"${id}\"`;
|
|
197
|
+
const result = await arquery.executeARQuery(formConfig.formName, clientConfig[formConfig.configName].basequery || null, query , '1', {limit:1})
|
|
198
|
+
if (result && result.data && result.data.length >0) {
|
|
199
|
+
return Object.values(result.data[0])[0]
|
|
200
|
+
}
|
|
201
|
+
throw new Error (`Internal Id for Record ${id} in Form ${formConfig.formName} could not be found`)
|
|
202
|
+
}
|
|
203
|
+
|
|
182
204
|
function searchRecords(formConfig, clientConfig, searchString, fields, options, includeString, globalScriptParams) {
|
|
183
205
|
const mapping = formConfig.mapping
|
|
184
206
|
const mappedString = searchUtil.applyCustomFormMapping(searchString, mapping);
|
package/docs/releases.md
CHANGED
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
## API
|
|
4
4
|
|
|
5
|
+
### 1.50.0 - 05.11.21
|
|
6
|
+
Use custom defined id in customForms
|
|
7
|
+
|
|
5
8
|
### 1.49.2 - 05.11.21
|
|
6
|
-
Fix issue:
|
|
9
|
+
Fix issue: Custom classAttributes not working in cmdbObjects PUT & POST
|
|
7
10
|
|
|
8
11
|
### 1.49.1 - 04.11.21
|
|
9
12
|
Fix issue: Self Mapping in custom Forms removed attribute
|
package/package.json
CHANGED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
const assert = require('chai').assert;
|
|
2
|
+
let chai = require('chai');
|
|
3
|
+
let chaiHttp = require('chai-http');
|
|
4
|
+
let should = chai.should();
|
|
5
|
+
let server = require('../app');
|
|
6
|
+
const TestUtils = require('./testUtils')
|
|
7
|
+
require('dotenv').config();
|
|
8
|
+
|
|
9
|
+
//Integrations Tests here
|
|
10
|
+
|
|
11
|
+
chai.use(chaiHttp);
|
|
12
|
+
|
|
13
|
+
describe('Integration Tests - customForms', function () {
|
|
14
|
+
|
|
15
|
+
let authUser = {'id':process.env.TEST_ID, 'secret':process.env.TEST_SECRET};
|
|
16
|
+
|
|
17
|
+
before((done) => {
|
|
18
|
+
|
|
19
|
+
// Authenticate the user to get a token
|
|
20
|
+
TestUtils.authenticateUser(authUser, server)
|
|
21
|
+
.then((accessToken) => {
|
|
22
|
+
// Keep the token on the user so we can use it in the tests
|
|
23
|
+
authUser.access_token = accessToken;
|
|
24
|
+
return done();
|
|
25
|
+
})
|
|
26
|
+
.catch((err) => done(err));
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('GET custom Form Data', function () {
|
|
30
|
+
it ('it should get a spezific record by id', function (done) {
|
|
31
|
+
chai.request(server)
|
|
32
|
+
.get('/v1/customForms/persons/rhannemann')
|
|
33
|
+
.set('Authorization', 'Bearer ' + authUser.access_token)
|
|
34
|
+
.end(function(err, res) {
|
|
35
|
+
res.should.have.status(200);
|
|
36
|
+
res.body.data.should.be.an('object');
|
|
37
|
+
res.body.data.should.have.property('name');
|
|
38
|
+
res.body.data.should.have.property('id');
|
|
39
|
+
done();
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it ('it should get all customForm records', function (done) {
|
|
44
|
+
chai.request(server)
|
|
45
|
+
.get('/v1/customForms/persons?limit=5')
|
|
46
|
+
.set('Authorization', 'Bearer ' + authUser.access_token)
|
|
47
|
+
.end(function(err, res) {
|
|
48
|
+
res.should.have.status(200);
|
|
49
|
+
res.body.data.should.be.an('array');
|
|
50
|
+
res.body.data.length.should.be.above(0);
|
|
51
|
+
done();
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it ('it should search customForms', function (done) {
|
|
56
|
+
const searchString = `'name' LIKE "Robert Hannemann%"`;
|
|
57
|
+
chai.request(server)
|
|
58
|
+
.post('/v1/customForms/persons/search')
|
|
59
|
+
.set('Authorization', 'Bearer ' + authUser.access_token)
|
|
60
|
+
.send({searchString})
|
|
61
|
+
.end(function(err, res) {
|
|
62
|
+
res.should.have.status(200);
|
|
63
|
+
res.body.data.should.be.an('array');
|
|
64
|
+
res.body.data.length.should.be.above(0);
|
|
65
|
+
done();
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it ('it should update a customForm Record by id', function (done) {
|
|
70
|
+
const data = {
|
|
71
|
+
name: 'Robert Hannemann' + new Date()
|
|
72
|
+
}
|
|
73
|
+
chai.request(server)
|
|
74
|
+
.put('/v1/customForms/persons/rhannemann')
|
|
75
|
+
.set('Authorization', 'Bearer ' + authUser.access_token)
|
|
76
|
+
.send({data})
|
|
77
|
+
.end(function(err, res) {
|
|
78
|
+
res.should.have.status(200);
|
|
79
|
+
res.body.data.should.be.an('object');
|
|
80
|
+
res.body.data.should.have.property('name');
|
|
81
|
+
res.body.data.should.have.property('id');
|
|
82
|
+
res.body.data.name.should.be.equal(data.name)
|
|
83
|
+
done();
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it ('it should create a customForm Record', function (done) {
|
|
88
|
+
const data = {
|
|
89
|
+
"userId": "Demo",
|
|
90
|
+
"classId": "00001",
|
|
91
|
+
"Department": "Mux",
|
|
92
|
+
"classTitle": "Blup",
|
|
93
|
+
"cost": 55,
|
|
94
|
+
"location": "Muc",
|
|
95
|
+
"startDate": "Mon Nov 07 16:00:00 GMT 2005"
|
|
96
|
+
}
|
|
97
|
+
chai.request(server)
|
|
98
|
+
.post('/v1/customForms/enrollments')
|
|
99
|
+
.set('Authorization', 'Bearer ' + authUser.access_token)
|
|
100
|
+
.send({data})
|
|
101
|
+
.end(function(err, res) {
|
|
102
|
+
res.should.have.status(200);
|
|
103
|
+
res.body.data.should.be.an('object');
|
|
104
|
+
res.body.data.should.have.property('location');
|
|
105
|
+
res.body.data.should.have.property('id');
|
|
106
|
+
res.body.data.location.should.be.equal(data.location)
|
|
107
|
+
done();
|
|
108
|
+
})
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
})
|