@isoftdata/utility-dashboard-backend 1.0.3 → 1.1.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/index.js +18 -16
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -81,7 +81,7 @@ const loadOptionList = async(mysqlConnection, optionListQuery, optionList = [])
|
|
|
81
81
|
]
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
const loadOutputParameterValues = async(mysqlConnection, definitionList, selectionList = []) => {
|
|
84
|
+
const loadOutputParameterValues = async(mysqlConnection, { definitionList, selectionList = [], forClient = false }) => {
|
|
85
85
|
let parameterValues = []
|
|
86
86
|
|
|
87
87
|
for (const definition of definitionList) {
|
|
@@ -102,20 +102,25 @@ const loadOutputParameterValues = async(mysqlConnection, definitionList, selecti
|
|
|
102
102
|
if (parameter.value !== 'Custom') {
|
|
103
103
|
parameter.dates = datesFromRange(parameter.value)
|
|
104
104
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
if (!forClient) {
|
|
106
|
+
parameter.queryValues = {
|
|
107
|
+
[`${parameter.name}_start_date`]: parameter.dates.from,
|
|
108
|
+
[`${parameter.name}_end_date`]: parameter.dates.to,
|
|
109
|
+
}
|
|
108
110
|
}
|
|
109
111
|
} else if (definition.type === 'selection') {
|
|
110
112
|
parameter.optionList = await loadOptionList(mysqlConnection, definition.optionListQuery, definition.optionList) // queries db
|
|
111
|
-
|
|
112
|
-
|
|
113
|
+
if (!forClient) {
|
|
114
|
+
parameter.queryValues = {
|
|
115
|
+
[parameter.name]: parameter.value,
|
|
116
|
+
}
|
|
113
117
|
}
|
|
114
118
|
} else if (definition.type === 'date') {
|
|
115
119
|
parameter.value = parameter.value || formatDate(new Date(), 'yyyy-MM-dd')
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
120
|
+
if (!forClient) {
|
|
121
|
+
parameter.queryValues = {
|
|
122
|
+
[parameter.name]: parameter.value,
|
|
123
|
+
}
|
|
119
124
|
}
|
|
120
125
|
}
|
|
121
126
|
|
|
@@ -150,18 +155,14 @@ const parameterizeQuery = (query, parameterValues) => {
|
|
|
150
155
|
module.exports = {
|
|
151
156
|
formatReportMetadata: async(mysqlConnection, { report, chartsInReport }) => {
|
|
152
157
|
try {
|
|
153
|
-
const parameterValues = await loadOutputParameterValues(mysqlConnection, report.parameters)
|
|
154
|
-
const parameterValuesForClient = parameterValues.map(param => {
|
|
155
|
-
const { queryValues, ...parameterValuesForClient } = param
|
|
156
|
-
return parameterValuesForClient
|
|
157
|
-
})
|
|
158
|
+
const parameterValues = await loadOutputParameterValues(mysqlConnection, { definitionList: report.parameters, forClient: true })
|
|
158
159
|
|
|
159
160
|
return {
|
|
160
161
|
dashboardReportId: report.dashboardReportId,
|
|
161
162
|
name: report.reportName,
|
|
162
163
|
title: report.reportTitle,
|
|
163
164
|
charts: chartsInReport,
|
|
164
|
-
parameterValues
|
|
165
|
+
parameterValues,
|
|
165
166
|
ownerId: report.ownerId,
|
|
166
167
|
}
|
|
167
168
|
} catch (err) {
|
|
@@ -171,7 +172,7 @@ module.exports = {
|
|
|
171
172
|
},
|
|
172
173
|
formatChartDataForReport: async(mysqlConnection, { reportParameters, chart, reportChart, parameterSelectionList }) => {
|
|
173
174
|
try {
|
|
174
|
-
const parameterValues = await loadOutputParameterValues(mysqlConnection, reportParameters, parameterSelectionList)
|
|
175
|
+
const parameterValues = await loadOutputParameterValues(mysqlConnection, { definitionList: reportParameters, selectionList: parameterSelectionList })
|
|
175
176
|
return await loadChartData(mysqlConnection, {
|
|
176
177
|
...chart,
|
|
177
178
|
reportChartId: reportChart.reportChartId,
|
|
@@ -183,4 +184,5 @@ module.exports = {
|
|
|
183
184
|
throw err
|
|
184
185
|
}
|
|
185
186
|
},
|
|
187
|
+
loadOutputParameterValues,
|
|
186
188
|
}
|
package/package.json
CHANGED