@manyos/smileconnect-api 1.49.2 → 1.51.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/conf/clients.json CHANGED
@@ -198,7 +198,7 @@
198
198
  "script2"
199
199
  ],
200
200
  "postMapping": [
201
- "script2"
201
+ "script1"
202
202
  ]
203
203
  },
204
204
  "POST": {
@@ -1,2 +1 @@
1
- //requestData.Name = "Horstdidü";
2
- resolve();
1
+ // requestData.Name = "Horstdidü";
@@ -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 query = `'1'=\"${id}\"`;
145
- const returnValue = await queryRecords(formConfig, clientConfig, query, mapping, null, null, includeString, globalScriptParams);
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 update = await arquery.updateEntry(formConfig.formName, id, recordData);
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/adapter.md CHANGED
@@ -221,6 +221,66 @@ const resultUpdate = await adapter.remedy.update(settings.form, settings.id, set
221
221
 
222
222
  Will return return the id of the updated record. e.g. 000000000000115 or throw an error.
223
223
 
224
+ ### getAttachment
225
+
226
+ ```javascript
227
+ async getAttachment(form, entryId, attachmentFieldId, options)
228
+ ```
229
+
230
+ Parameter:
231
+
232
+ * form (string):
233
+
234
+ The form used to where the attachmentField is on
235
+
236
+ * entryId (string):
237
+
238
+ The id of the record on which the attachment is on
239
+
240
+ * attachmentFieldId:
241
+
242
+ The id of the attachment field
243
+
244
+ Full example:
245
+ ```javascript
246
+ const file = adapter.remedy.getAttachment('CHG:WorkLog', 'CWL000000002484', '1000000353')
247
+ const fileName = file.name
248
+ const fileData = file.data
249
+ ```
250
+
251
+ ### setAttachment
252
+
253
+ ```javascript
254
+ async getAttachment(form, entryId, attachmentFieldId, file, options)
255
+ ```
256
+
257
+ Parameter:
258
+
259
+ * form (string):
260
+
261
+ The form used to where the attachmentField is on
262
+
263
+ * entryId (string):
264
+
265
+ The id of the record on which the attachment is on
266
+
267
+ * attachmentFieldId:
268
+
269
+ The id of the attachment field
270
+
271
+ * file
272
+
273
+ An Object containing the file
274
+
275
+ Full example:
276
+ ```javascript
277
+ const file = {
278
+ data: fs.readFileSync('test/files/logo.png'),
279
+ name: 'logo.png',
280
+ mimetype: 'image/png'
281
+ };
282
+ await adapter.remedy.setAttachment('CHG:WorkLog', 'CWL000000002484', '1000000353', file)
283
+ ```
224
284
 
225
285
  ### Options
226
286
 
package/docs/releases.md CHANGED
@@ -2,8 +2,14 @@
2
2
 
3
3
  ## API
4
4
 
5
+ ### 1.50.1 - 05.11.21
6
+ Add setAttachment & getAttachment to Remedy Adapter
7
+
8
+ ### 1.50.0 - 05.11.21
9
+ Use custom defined id in customForms
10
+
5
11
  ### 1.49.2 - 05.11.21
6
- Fix issue: Class specific Attributes not working in CMDBObject create & update
12
+ Fix issue: Custom classAttributes not working in cmdbObjects PUT & POST
7
13
 
8
14
  ### 1.49.1 - 04.11.21
9
15
  Fix issue: Self Mapping in custom Forms removed attribute
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manyos/smileconnect-api",
3
- "version": "1.49.2",
3
+ "version": "1.51.0",
4
4
  "description": "A proxy and abstraction layer for BMCs IT Service Management Suite",
5
5
  "main": "app.js",
6
6
  "scripts": {
@@ -38,7 +38,7 @@
38
38
  "request-promise-native": "^1.0.9",
39
39
  "socket.io": "^2.4.1",
40
40
  "uuid": "^3.4.0",
41
- "vm2": "3.9.3"
41
+ "vm2": "^3.9.5"
42
42
  },
43
43
  "devDependencies": {
44
44
  "chai": "^4.3.4",
@@ -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
+ })