@isoftdata/utility-dashboard-backend 3.2.21 → 3.2.22
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/README.md +29 -13
- package/dist/types/parameter.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# utility-dashboard-backend
|
|
2
|
+
|
|
2
3
|
A backend utility for formatting and loading dashboard chart and report data to be usable by the [frontend dashboard component](https://github.com/ISoft-Data-Systems/ractive-component-web-dashboard).
|
|
3
4
|
|
|
4
5
|
## Installation
|
|
@@ -10,7 +11,9 @@ npm i @isoftdata/utility-dashboard-backend
|
|
|
10
11
|
> Breaking change in version 3: ESM style exports
|
|
11
12
|
|
|
12
13
|
## Prerequisites
|
|
14
|
+
>
|
|
13
15
|
> Version 3.Y.Z of the frontend component is required for use with version 2.Y.Z of the backend component.
|
|
16
|
+
|
|
14
17
|
* A MySQL database schema as outlined in [schema.md](schema.md)
|
|
15
18
|
* A backend that can fetches rows from the chart, report, and report chart tables from the database with their primary keys. Any json columns should be parsed as objects.
|
|
16
19
|
* A connection or pool of connections from the `mysql` NPM module for running the charts' queries
|
|
@@ -32,13 +35,14 @@ async formatReportMetadata(mysqlConnection, { report, chartsInReport, session })
|
|
|
32
35
|
|
|
33
36
|
```js
|
|
34
37
|
async function loadReportMetadata({ dashboardReportId, chartId, session }) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
const report = await db.dashboardReport.loadById({ dashboardReportId }) // gets a report by its id
|
|
39
|
+
const chartsInReport = await db.dashboardChart.loadByReport({ dashboardReportId, chartId }) // gets all charts for a specified report, or if `chartId` is specified, only gets that chart for that report.
|
|
40
|
+
return await formatReportMetadata(db.pool, { report, chartsInReport, session })
|
|
38
41
|
}
|
|
39
42
|
```
|
|
40
43
|
|
|
41
44
|
#### mysqlConnection
|
|
45
|
+
|
|
42
46
|
A connection or pool of connections from the `mysql` npm module.
|
|
43
47
|
|
|
44
48
|
#### report
|
|
@@ -102,13 +106,19 @@ Example:
|
|
|
102
106
|
```
|
|
103
107
|
|
|
104
108
|
#### session
|
|
109
|
+
|
|
105
110
|
Session object from the Auth Module
|
|
106
111
|
|
|
107
112
|
#### site (optional)
|
|
113
|
+
|
|
108
114
|
The 'type' of site for the product this is used in. Determines the MySQL table to query for site selection parameters, and used to calculate `siteIdColumn` if that is not specified.
|
|
115
|
+
|
|
109
116
|
#### siteIdColumn (optional)
|
|
117
|
+
|
|
110
118
|
The name of the column that stores the site id in the site table. Defaults to `${site}id`.
|
|
119
|
+
|
|
111
120
|
#### siteNameColumn (optional)
|
|
121
|
+
|
|
112
122
|
The store name column.
|
|
113
123
|
|
|
114
124
|
### formatChartDataForReport
|
|
@@ -125,32 +135,37 @@ async formatChartDataForReport(mysqlConnection, { reportParameters, chart, repor
|
|
|
125
135
|
|
|
126
136
|
```js
|
|
127
137
|
async function loadChartDataForReport ({ dashboardReportId, chartId, parameterSelectionList, session }) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
+
const report = await db.dashboardReport.loadById({ dashboardReportId }) // get the report object
|
|
139
|
+
const chart = await db.dashboardChart.loadById({ chartId }) // get the chart object
|
|
140
|
+
const reportChart = await db.dashboardReportChart.loadByReportAndChartId({ chartId, dashboardReportId }) // get the report chart for the rank/overrides
|
|
141
|
+
try {
|
|
142
|
+
const chartData = await formatChartDataForReport(db.pool, { reportParameters: report.parameters, chart, reportChart, parameterSelectionList, session })
|
|
143
|
+
return chartData
|
|
144
|
+
} catch (err) {
|
|
145
|
+
console.error(err)
|
|
146
|
+
return { isErrored: true }
|
|
147
|
+
}
|
|
138
148
|
}
|
|
139
149
|
```
|
|
140
150
|
|
|
141
151
|
#### mysqlConnection
|
|
152
|
+
|
|
142
153
|
A connection or pool of connections from the `mysql` npm module.
|
|
143
154
|
|
|
144
155
|
#### reportParameters
|
|
156
|
+
|
|
145
157
|
The `parameters` array from a report object.
|
|
146
158
|
|
|
147
159
|
#### chartId
|
|
160
|
+
|
|
148
161
|
The id of a chart row in `wa_dashboard_chart`.
|
|
149
162
|
|
|
150
163
|
#### parameterSelectionList
|
|
164
|
+
|
|
151
165
|
The array of selected parameters sent from the client dashboard.
|
|
152
166
|
|
|
153
167
|
#### session
|
|
168
|
+
|
|
154
169
|
Session object from the Auth Module
|
|
155
170
|
|
|
156
171
|
### loadOutputParameterValues
|
|
@@ -166,6 +181,7 @@ async function loadOutputParameterValues(mysqlConnection, { definitionList, sele
|
|
|
166
181
|
#### Example Usage
|
|
167
182
|
|
|
168
183
|
#### mysqlConnection
|
|
184
|
+
|
|
169
185
|
A connection or pool of connections from the `mysql` npm module.
|
|
170
186
|
|
|
171
187
|
#### definitionList
|
package/package.json
CHANGED