1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | 'use strict';
|
7 |
|
8 | var _ = require('lodash');
|
9 | var config = require('./test-config');
|
10 |
|
11 | var api = require('./index').configure(
|
12 | config.PSA_SERVER_HOST,
|
13 | config.INTEGRATION_COMPANY_NAME,
|
14 | config.INTEGRATION_LOGIN_ID,
|
15 | config.INTEGRATION_PASSWORD
|
16 | );
|
17 |
|
18 | function sortAvailableReports(normalizedReports) {
|
19 | var sortMap = function (map) {
|
20 | return _(map).keys().sort().reduce(function (sortedMap, key) {
|
21 | sortedMap[key] = map[key];
|
22 | return sortedMap;
|
23 | }, {});
|
24 | };
|
25 |
|
26 | return sortMap(_.transform(normalizedReports, function (reports, report, reportName) {
|
27 | reports[reportName] = sortMap(report);
|
28 | }));
|
29 | }
|
30 |
|
31 | function markdownAvailableReports(normalizedReports) {
|
32 | return _.reduce(normalizedReports, function (markdown, fields, reportName) {
|
33 | markdown += '#### ' + reportName + '\r\n';
|
34 | markdown += '| | | |\r\n' +
|
35 | '|-------------|-------------|-----|\r\n';
|
36 | markdown += _.reduce(fields, function (markdown, attributes, fieldName) {
|
37 | markdown += '| `' + fieldName + '` | ' + attributes.Type + ' | ' + (attributes.IsNullable.toLowerCase() === 'true' ? 'nullable' : '') + ' |\r\n';
|
38 | return markdown;
|
39 | }, '') + '\r\n';
|
40 | return markdown;
|
41 | }, '');
|
42 | }
|
43 |
|
44 | api.action('GetConnectWiseVersionAction', {}, function (error, result) {
|
45 | error && console.error(error);
|
46 | if (!result) { return; }
|
47 |
|
48 | console.log('### Available Reports for ConnectWise ' + result.GetConnectWiseVersionAction.CwVersionInfo.Version);
|
49 | console.log('---');
|
50 |
|
51 | api.action('GetAvailableReportsAction', { IncludeFields: true }, function (error, response) {
|
52 | error && console.error(error);
|
53 | if (response) {
|
54 | var reports = api.normalizeGetAvailableReportsActionResponse(response);
|
55 | reports = sortAvailableReports(reports);
|
56 | console.log(markdownAvailableReports(reports));
|
57 | }
|
58 | });
|
59 | }); |
\ | No newline at end of file |