@ministryofjustice/hmpps-digital-prison-reporting-frontend 4.2.1 → 4.2.2

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.
@@ -60,7 +60,7 @@
60
60
  {{ dprRequestDetails(data)}}
61
61
 
62
62
  {{ govukInsetText({
63
- html: "<p>It can take up to 10 minutes to generate a " + type + ".</p> <p>You can close and revisit this page at anytime. Navigate to the homepage to check on its status or your " + type + ".</p>"
63
+ html: "<p>It can take up to 10 minutes to generate a " + type + ".</p> <p>You can close and revisit this page at anytime. Navigate to the homepage to check on the status of your " + type + ".</p>"
64
64
  }) }}
65
65
 
66
66
  {{ govukButton({
@@ -59,7 +59,6 @@ const updateStore = async ({ req, res, services, queryData, executionData, child
59
59
  default:
60
60
  break;
61
61
  }
62
- console.log(JSON.stringify(requestedReportData, null, 2));
63
62
  await services.requestedReportService.addReport(userId, requestedReportData);
64
63
  return requestedReportData.url.polling.pathname;
65
64
  };
@@ -85,8 +85,6 @@ export const updateStore = async ({
85
85
  break
86
86
  }
87
87
 
88
- console.log(JSON.stringify(requestedReportData, null, 2))
89
-
90
88
  await services.requestedReportService.addReport(userId, requestedReportData)
91
89
 
92
90
  return requestedReportData.url.polling.pathname
@@ -70,7 +70,7 @@ const formatTableData = async (bookmarksData, bookmarkService, csrfToken, userId
70
70
  };
71
71
  const mapBookmarkIdsToDefinition = async (bookmarks, req, res, token, services) => {
72
72
  const bookmarkData = [];
73
- const { pathSuffix, definitionsPath } = localsHelper_1.default.getValues(res);
73
+ const { definitionsPath } = localsHelper_1.default.getValues(res);
74
74
  await Promise.all(bookmarks.map(async (bookmark) => {
75
75
  var _a;
76
76
  let definition;
@@ -122,7 +122,6 @@ const mapBookmarkIdsToDefinition = async (bookmarks, req, res, token, services)
122
122
  exports.default = {
123
123
  renderBookmarkList: async ({ services, maxRows, res, req, }) => {
124
124
  const { token, csrfToken, userId, bookmarks } = localsHelper_1.default.getValues(res);
125
- console.log({ bookmarks });
126
125
  const bookmarksData = await mapBookmarkIdsToDefinition(bookmarks, req, res, token, services);
127
126
  const formatted = await (0, exports.formatBookmarks)(bookmarksData, maxRows);
128
127
  const tableData = await formatTable(bookmarksData, services.bookmarkService, csrfToken, userId, maxRows);
@@ -96,7 +96,7 @@ const mapBookmarkIdsToDefinition = async (
96
96
  services: Services,
97
97
  ): Promise<BookmarkedReportData[]> => {
98
98
  const bookmarkData: BookmarkedReportData[] = []
99
- const { pathSuffix, definitionsPath } = LocalsHelper.getValues(res)
99
+ const { definitionsPath } = LocalsHelper.getValues(res)
100
100
 
101
101
  await Promise.all(
102
102
  bookmarks.map(async (bookmark) => {
@@ -180,9 +180,6 @@ export default {
180
180
  req: Request
181
181
  }) => {
182
182
  const { token, csrfToken, userId, bookmarks } = LocalsHelper.getValues(res)
183
-
184
- console.log({ bookmarks })
185
-
186
183
  const bookmarksData: BookmarkedReportData[] = await mapBookmarkIdsToDefinition(bookmarks, req, res, token, services)
187
184
  const formatted = await formatBookmarks(bookmarksData, maxRows)
188
185
  const tableData = await formatTable(bookmarksData, services.bookmarkService, csrfToken, userId, maxRows)
@@ -10,7 +10,7 @@ class DashboardClient {
10
10
  this.restClient = new restClient_1.default('Dashboard API Client', config);
11
11
  }
12
12
  getDefinition(token, dashboardId, dpdId, definitionsPath) {
13
- this.logInfo('Get definition:', { dpdId, dashboardId }, { definitionsPath });
13
+ this.logInfo('Get definition:', { dpdId, dashboardId });
14
14
  const query = {
15
15
  dataProductDefinitionsPath: definitionsPath,
16
16
  };
@@ -23,7 +23,7 @@ class DashboardClient {
23
23
  .then((response) => response);
24
24
  }
25
25
  requestAsyncDashboard(token, reportId, dashboardId, query) {
26
- this.logInfo('Request dashboard:', { reportId, dashboardId }, query);
26
+ this.logInfo('Request dashboard:', { reportId, dashboardId });
27
27
  return this.restClient
28
28
  .get({
29
29
  path: `/async/dashboards/${reportId}/${dashboardId}`,
@@ -33,7 +33,7 @@ class DashboardClient {
33
33
  .then((response) => response);
34
34
  }
35
35
  getAsyncDashboard(token, reportId, dashboardId, tableId, query) {
36
- this.logInfo('Get dashboard:', { reportId, dashboardId, tableId }, query);
36
+ this.logInfo('Get dashboard:', { reportId, dashboardId, tableId });
37
37
  return this.restClient
38
38
  .get({
39
39
  path: `/reports/${reportId}/dashboards/${dashboardId}/tables/${tableId}/result`,
@@ -43,7 +43,7 @@ class DashboardClient {
43
43
  .then((response) => response);
44
44
  }
45
45
  getAsyncStatus(token, reportId, dashboardId, executionId, dataProductDefinitionsPath, tableId) {
46
- this.logInfo('Get status:', { reportId, dashboardId, executionId, tableId }, { dataProductDefinitionsPath });
46
+ this.logInfo('Get status:', { reportId, dashboardId, executionId, tableId });
47
47
  return this.restClient
48
48
  .get({
49
49
  path: `/reports/${reportId}/dashboards/${dashboardId}/statements/${executionId}/status`,
@@ -56,7 +56,7 @@ class DashboardClient {
56
56
  .then((response) => response);
57
57
  }
58
58
  cancelAsyncRequest(token, reportId, dashboardId, executionId, dataProductDefinitionsPath) {
59
- this.logInfo('Cancel request:', { reportId, dashboardId, executionId }, { dataProductDefinitionsPath });
59
+ this.logInfo('Cancel request:', { reportId, dashboardId, executionId });
60
60
  return this.restClient
61
61
  .delete({
62
62
  path: `/reports/${reportId}/dashboards/${dashboardId}/statements/${executionId}`,
@@ -67,13 +67,10 @@ class DashboardClient {
67
67
  })
68
68
  .then((response) => response);
69
69
  }
70
- logInfo(title, args, query) {
71
- logger_1.default.info(`
72
- Dashboard client: ${title}:`);
73
- logger_1.default.info(JSON.stringify(args, null, 2));
74
- if (query) {
75
- logger_1.default.info(JSON.stringify(query, null, 2));
76
- }
70
+ logInfo(title, args) {
71
+ logger_1.default.info(`Dashboard client: ${title}:`);
72
+ if (args && Object.keys(args).length)
73
+ logger_1.default.info(JSON.stringify(args, null, 2));
77
74
  }
78
75
  }
79
76
  exports.default = DashboardClient;
@@ -17,7 +17,7 @@ export default class DashboardClient {
17
17
  dpdId: string,
18
18
  definitionsPath?: string,
19
19
  ): Promise<DashboardDefinition> {
20
- this.logInfo('Get definition:', { dpdId, dashboardId }, { definitionsPath })
20
+ this.logInfo('Get definition:', { dpdId, dashboardId })
21
21
  const query = {
22
22
  dataProductDefinitionsPath: definitionsPath,
23
23
  }
@@ -36,7 +36,7 @@ export default class DashboardClient {
36
36
  dashboardId: string,
37
37
  query: Record<string, string | boolean | number>,
38
38
  ): Promise<Dict<string>> {
39
- this.logInfo('Request dashboard:', { reportId, dashboardId }, query)
39
+ this.logInfo('Request dashboard:', { reportId, dashboardId })
40
40
 
41
41
  return this.restClient
42
42
  .get({
@@ -54,7 +54,7 @@ export default class DashboardClient {
54
54
  tableId: string,
55
55
  query: Dict<string | number>,
56
56
  ): Promise<Array<Dict<string>>> {
57
- this.logInfo('Get dashboard:', { reportId, dashboardId, tableId }, query)
57
+ this.logInfo('Get dashboard:', { reportId, dashboardId, tableId })
58
58
 
59
59
  return this.restClient
60
60
  .get({
@@ -73,7 +73,7 @@ export default class DashboardClient {
73
73
  dataProductDefinitionsPath?: string,
74
74
  tableId?: string,
75
75
  ): Promise<Dict<string>> {
76
- this.logInfo('Get status:', { reportId, dashboardId, executionId, tableId }, { dataProductDefinitionsPath })
76
+ this.logInfo('Get status:', { reportId, dashboardId, executionId, tableId })
77
77
 
78
78
  return this.restClient
79
79
  .get({
@@ -94,7 +94,7 @@ export default class DashboardClient {
94
94
  executionId: string,
95
95
  dataProductDefinitionsPath: string,
96
96
  ): Promise<Dict<string>> {
97
- this.logInfo('Cancel request:', { reportId, dashboardId, executionId }, { dataProductDefinitionsPath })
97
+ this.logInfo('Cancel request:', { reportId, dashboardId, executionId })
98
98
 
99
99
  return this.restClient
100
100
  .delete({
@@ -107,12 +107,8 @@ export default class DashboardClient {
107
107
  .then((response) => <Dict<string>>response)
108
108
  }
109
109
 
110
- logInfo(title: string, args?: Dict<string>, query?: Dict<string | number | boolean>) {
111
- logger.info(`
112
- Dashboard client: ${title}:`)
113
- logger.info(JSON.stringify(args, null, 2))
114
- if (query) {
115
- logger.info(JSON.stringify(query, null, 2))
116
- }
110
+ logInfo(title: string, args?: Dict<string>) {
111
+ logger.info(`Dashboard client: ${title}:`)
112
+ if (args && Object.keys(args).length) logger.info(JSON.stringify(args, null, 2))
117
113
  }
118
114
  }
@@ -38,7 +38,7 @@ class ReportingClient {
38
38
  }));
39
39
  }
40
40
  getDefinitions(token, definitionsPath) {
41
- this.logInfo('Get definitions:', {}, { definitionsPath });
41
+ this.logInfo('Get definitions', { definitionsPath });
42
42
  const params = {
43
43
  query: {
44
44
  renderMethod: 'HTML',
@@ -54,10 +54,10 @@ class ReportingClient {
54
54
  .then((response) => response);
55
55
  }
56
56
  getDefinition(token, reportId, variantId, definitionsPath) {
57
- this.logInfo('Get single variant definition:', { reportId, variantId }, { definitionsPath });
58
57
  const query = {
59
58
  dataProductDefinitionsPath: definitionsPath,
60
59
  };
60
+ this.logInfo('Get definition', { reportId, variantId });
61
61
  return this.restClient
62
62
  .get({
63
63
  path: `/definitions/${reportId}/${variantId}`,
@@ -71,7 +71,7 @@ class ReportingClient {
71
71
  dataProductDefinitionsPath: definitionsPath,
72
72
  prefix,
73
73
  };
74
- this.logInfo('Get field values:', { definitionName, variantName, fieldName }, query);
74
+ this.logInfo('Get field values', { definitionName, variantName, fieldName, prefix });
75
75
  return this.restClient
76
76
  .get({
77
77
  path: `/reports/${definitionName}/${variantName}/${fieldName}`,
@@ -81,7 +81,7 @@ class ReportingClient {
81
81
  .then((response) => response);
82
82
  }
83
83
  requestAsyncReport(token, reportId, variantId, query) {
84
- this.logInfo('Request report:', { reportId, variantId }, query);
84
+ this.logInfo('Request report', { reportId, variantId });
85
85
  return this.restClient
86
86
  .get({
87
87
  path: `/async/reports/${reportId}/${variantId}`,
@@ -91,7 +91,7 @@ class ReportingClient {
91
91
  .then((response) => response);
92
92
  }
93
93
  cancelAsyncRequest(token, reportId, variantId, executionId, dataProductDefinitionsPath) {
94
- this.logInfo('Cancel request:', { reportId, variantId, executionId }, { dataProductDefinitionsPath });
94
+ this.logInfo('Cancel Request', { reportId, variantId, executionId });
95
95
  return this.restClient
96
96
  .delete({
97
97
  path: `/reports/${reportId}/${variantId}/statements/${executionId}`,
@@ -103,7 +103,7 @@ class ReportingClient {
103
103
  .then((response) => response);
104
104
  }
105
105
  getAsyncReport(token, reportId, variantId, tableId, query) {
106
- this.logInfo('Get Data:', { reportId, variantId, tableId }, query);
106
+ this.logInfo('Get Data', { reportId, variantId, tableId });
107
107
  return this.restClient
108
108
  .get({
109
109
  path: `/reports/${reportId}/${variantId}/tables/${tableId}/result`,
@@ -113,7 +113,7 @@ class ReportingClient {
113
113
  .then((response) => response);
114
114
  }
115
115
  getAsyncSummaryReport(token, reportId, variantId, tableId, summaryId, query) {
116
- this.logInfo('Get summary report data:', { reportId, variantId, summaryId, tableId }, query);
116
+ this.logInfo('Get summary data', { reportId, variantId, tableId, summaryId });
117
117
  return this.restClient
118
118
  .get({
119
119
  path: `/reports/${reportId}/${variantId}/tables/${tableId}/result/summary/${summaryId}`,
@@ -123,7 +123,7 @@ class ReportingClient {
123
123
  .then((response) => response);
124
124
  }
125
125
  getAsyncReportStatus(token, reportId, variantId, executionId, dataProductDefinitionsPath, tableId) {
126
- this.logInfo('Get status:', { reportId, variantId, executionId, tableId }, { dataProductDefinitionsPath });
126
+ this.logInfo('Get status', { reportId, variantId, tableId, executionId });
127
127
  return this.restClient
128
128
  .get({
129
129
  path: `/reports/${reportId}/${variantId}/statements/${executionId}/status`,
@@ -136,7 +136,7 @@ class ReportingClient {
136
136
  .then((response) => response);
137
137
  }
138
138
  getAsyncCount(token, tableId, dataProductDefinitionsPath) {
139
- this.logInfo('Get count:', { tableId });
139
+ this.logInfo('Get count', { tableId });
140
140
  return this.restClient
141
141
  .get({
142
142
  path: `/report/tables/${tableId}/count`,
@@ -148,7 +148,7 @@ class ReportingClient {
148
148
  .then((response) => response.count);
149
149
  }
150
150
  getAsyncInteractiveCount(token, tableId, reportId, id, filters) {
151
- this.logInfo('Get interactive count', { tableId });
151
+ this.logInfo('Get interactive count', { tableId, reportId, id });
152
152
  return this.restClient
153
153
  .get({
154
154
  path: `/reports/${reportId}/${id}/tables/${tableId}/count`,
@@ -157,13 +157,10 @@ class ReportingClient {
157
157
  })
158
158
  .then((response) => response.count);
159
159
  }
160
- logInfo(title, args, query) {
161
- logger_1.default.info(`
162
- Reporting client: ${title}:`);
163
- logger_1.default.info(JSON.stringify(args, null, 2));
164
- if (query) {
165
- logger_1.default.info(JSON.stringify(query, null, 2));
166
- }
160
+ logInfo(title, args) {
161
+ logger_1.default.info(`Reporting Client: ${title}:`);
162
+ if (args && Object.keys(args).length)
163
+ logger_1.default.info(JSON.stringify(args, null, 2));
167
164
  }
168
165
  }
169
166
  exports.default = ReportingClient;
@@ -50,7 +50,7 @@ export default class ReportingClient {
50
50
  token: string,
51
51
  definitionsPath?: string,
52
52
  ): Promise<Array<components['schemas']['ReportDefinitionSummary']>> {
53
- this.logInfo('Get definitions:', {}, { definitionsPath })
53
+ this.logInfo('Get definitions', { definitionsPath })
54
54
 
55
55
  const params: operations['definitions_1']['parameters'] = {
56
56
  query: {
@@ -74,11 +74,11 @@ export default class ReportingClient {
74
74
  variantId: string,
75
75
  definitionsPath?: string,
76
76
  ): Promise<components['schemas']['SingleVariantReportDefinition']> {
77
- this.logInfo('Get single variant definition:', { reportId, variantId }, { definitionsPath })
78
-
79
77
  const query = {
80
78
  dataProductDefinitionsPath: definitionsPath,
81
79
  }
80
+ this.logInfo('Get definition', { reportId, variantId })
81
+
82
82
  return this.restClient
83
83
  .get({
84
84
  path: `/definitions/${reportId}/${variantId}`,
@@ -100,7 +100,7 @@ export default class ReportingClient {
100
100
  dataProductDefinitionsPath: definitionsPath,
101
101
  prefix,
102
102
  }
103
- this.logInfo('Get field values:', { definitionName, variantName, fieldName }, query)
103
+ this.logInfo('Get field values', { definitionName, variantName, fieldName, prefix })
104
104
 
105
105
  return this.restClient
106
106
  .get({
@@ -117,7 +117,7 @@ export default class ReportingClient {
117
117
  variantId: string,
118
118
  query: Record<string, string | boolean | number>,
119
119
  ): Promise<Dict<string>> {
120
- this.logInfo('Request report:', { reportId, variantId }, query)
120
+ this.logInfo('Request report', { reportId, variantId })
121
121
 
122
122
  return this.restClient
123
123
  .get({
@@ -135,7 +135,7 @@ export default class ReportingClient {
135
135
  executionId: string,
136
136
  dataProductDefinitionsPath?: string,
137
137
  ): Promise<Dict<string>> {
138
- this.logInfo('Cancel request:', { reportId, variantId, executionId }, { dataProductDefinitionsPath })
138
+ this.logInfo('Cancel Request', { reportId, variantId, executionId })
139
139
 
140
140
  return this.restClient
141
141
  .delete({
@@ -155,7 +155,7 @@ export default class ReportingClient {
155
155
  tableId: string,
156
156
  query: Dict<string | number>,
157
157
  ): Promise<Array<Dict<string>>> {
158
- this.logInfo('Get Data:', { reportId, variantId, tableId }, query)
158
+ this.logInfo('Get Data', { reportId, variantId, tableId })
159
159
 
160
160
  return this.restClient
161
161
  .get({
@@ -174,7 +174,7 @@ export default class ReportingClient {
174
174
  summaryId: string,
175
175
  query: Dict<string | number>,
176
176
  ): Promise<Array<Dict<string>>> {
177
- this.logInfo('Get summary report data:', { reportId, variantId, summaryId, tableId }, query)
177
+ this.logInfo('Get summary data', { reportId, variantId, tableId, summaryId })
178
178
 
179
179
  return this.restClient
180
180
  .get({
@@ -193,7 +193,8 @@ export default class ReportingClient {
193
193
  dataProductDefinitionsPath?: string,
194
194
  tableId?: string,
195
195
  ): Promise<Dict<string>> {
196
- this.logInfo('Get status:', { reportId, variantId, executionId, tableId }, { dataProductDefinitionsPath })
196
+ this.logInfo('Get status', { reportId, variantId, tableId, executionId })
197
+
197
198
  return this.restClient
198
199
  .get({
199
200
  path: `/reports/${reportId}/${variantId}/statements/${executionId}/status`,
@@ -207,7 +208,7 @@ export default class ReportingClient {
207
208
  }
208
209
 
209
210
  getAsyncCount(token: string, tableId: string, dataProductDefinitionsPath?: string): Promise<number> {
210
- this.logInfo('Get count:', { tableId })
211
+ this.logInfo('Get count', { tableId })
211
212
 
212
213
  return this.restClient
213
214
  .get({
@@ -227,7 +228,7 @@ export default class ReportingClient {
227
228
  id: string,
228
229
  filters: ReportQuery,
229
230
  ): Promise<number> {
230
- this.logInfo('Get interactive count', { tableId })
231
+ this.logInfo('Get interactive count', { tableId, reportId, id })
231
232
 
232
233
  return this.restClient
233
234
  .get({
@@ -238,12 +239,8 @@ export default class ReportingClient {
238
239
  .then((response) => (<Count>response).count)
239
240
  }
240
241
 
241
- logInfo(title: string, args?: Dict<string>, query?: Dict<string | number | boolean>) {
242
- logger.info(`
243
- Reporting client: ${title}:`)
244
- logger.info(JSON.stringify(args, null, 2))
245
- if (query) {
246
- logger.info(JSON.stringify(query, null, 2))
247
- }
242
+ logInfo(title: string, args?: Dict<string>) {
243
+ logger.info(`Reporting Client: ${title}:`)
244
+ if (args && Object.keys(args).length) logger.info(JSON.stringify(args, null, 2))
248
245
  }
249
246
  }
@@ -13,10 +13,10 @@ const deriveDefinitionsPath = (query) => {
13
13
  // const dprExcludeRoutes = ['/getExpiredStatus/', '/getRequestedExpiredStatus/', '/getStatus/']
14
14
  exports.default = (services, config) => {
15
15
  return async (req, res, next) => {
16
- return (0, exports.populateDefinitions)(services, config, req, res, next);
16
+ return (0, exports.populateDefinitions)(services, req, res, next, config);
17
17
  };
18
18
  };
19
- const populateDefinitions = async (services, config, req, res, next) => {
19
+ const populateDefinitions = async (services, req, res, next, config) => {
20
20
  try {
21
21
  // Get the DPD path from the query
22
22
  const dpdPathFromQuery = deriveDefinitionsPath(req.query);
@@ -26,7 +26,7 @@ const populateDefinitions = async (services, config, req, res, next) => {
26
26
  res.locals.dpdPathFromQuery = true;
27
27
  }
28
28
  // Get the DPD path from the config
29
- const { dprDataProductDefinitionPath: dpdPathFromConfig } = config;
29
+ const dpdPathFromConfig = config === null || config === void 0 ? void 0 : config.dprDataProductDefinitionPath;
30
30
  if (dpdPathFromConfig) {
31
31
  res.locals.dpdPathFromConfig = true;
32
32
  }
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1
2
  import { NextFunction, RequestHandler, Response, Request } from 'express'
2
3
  import type { ParsedQs } from 'qs'
3
4
  import Dict = NodeJS.Dict
@@ -17,18 +18,18 @@ const deriveDefinitionsPath = (query: ParsedQs): string | null => {
17
18
 
18
19
  // const dprExcludeRoutes = ['/getExpiredStatus/', '/getRequestedExpiredStatus/', '/getStatus/']
19
20
 
20
- export default (services: Services, config: Dict<string>): RequestHandler => {
21
+ export default (services: Services, config?: any): RequestHandler => {
21
22
  return async (req, res, next) => {
22
- return populateDefinitions(services, config, req, res, next)
23
+ return populateDefinitions(services, req, res, next, config)
23
24
  }
24
25
  }
25
26
 
26
27
  export const populateDefinitions = async (
27
28
  services: Services,
28
- config: Dict<string>,
29
29
  req: Request,
30
30
  res: Response,
31
31
  next: NextFunction,
32
+ config?: any,
32
33
  ) => {
33
34
  try {
34
35
  // Get the DPD path from the query
@@ -41,7 +42,7 @@ export const populateDefinitions = async (
41
42
  }
42
43
 
43
44
  // Get the DPD path from the config
44
- const { dprDataProductDefinitionPath: dpdPathFromConfig } = config
45
+ const dpdPathFromConfig = config?.dprDataProductDefinitionPath
45
46
  if (dpdPathFromConfig) {
46
47
  res.locals.dpdPathFromConfig = true
47
48
  }
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.populateRequestedReports = void 0;
7
+ const definitionUtils_1 = __importDefault(require("../utils/definitionUtils"));
4
8
  exports.default = (services) => {
5
9
  return async (req, res, next) => {
6
10
  await (0, exports.populateRequestedReports)(services, req, res, next);
@@ -10,11 +14,27 @@ exports.default = (services) => {
10
14
  const populateRequestedReports = async (services, req, res, next) => {
11
15
  if (res.locals.user) {
12
16
  const { uuid: userId } = res.locals.user;
13
- res.locals.requestedReports = await services.requestedReportService.getAllReports(userId);
14
- res.locals.recentlyViewedReports = await services.recentlyViewedService.getAllReports(userId);
17
+ const { definitions, definitionsPath } = res.locals;
18
+ const requested = await services.requestedReportService.getAllReports(userId);
19
+ res.locals.requestedReports = !definitionsPath
20
+ ? requested
21
+ : requested.filter((report) => {
22
+ return definitionUtils_1.default.getCurrentVariantDefinition(definitions, report.reportId, report.id);
23
+ });
24
+ const recent = await services.recentlyViewedService.getAllReports(userId);
25
+ res.locals.recentlyViewedReports = !definitionsPath
26
+ ? recent
27
+ : recent.filter((report) => {
28
+ return definitionUtils_1.default.getCurrentVariantDefinition(definitions, report.reportId, report.id);
29
+ });
15
30
  if (services.bookmarkService) {
16
31
  res.locals.bookmarkingEnabled = true;
17
- res.locals.bookmarks = await services.bookmarkService.getAllBookmarks(userId);
32
+ const bookmarks = await services.bookmarkService.getAllBookmarks(userId);
33
+ res.locals.bookmarks = !definitionsPath
34
+ ? bookmarks
35
+ : bookmarks.filter((bookmark) => {
36
+ return definitionUtils_1.default.getCurrentVariantDefinition(definitions, bookmark.reportId, bookmark.id);
37
+ });
18
38
  }
19
39
  if (services.downloadPermissionService) {
20
40
  res.locals.downloadingEnabled = true;
@@ -1,5 +1,8 @@
1
1
  import { RequestHandler, NextFunction, Response, Request } from 'express'
2
2
  import { Services } from '../types/Services'
3
+ import { RequestedReport, StoredReportData } from '../types/UserReports'
4
+ import DefinitionUtils from '../utils/definitionUtils'
5
+ import { BookmarkStoreData } from '../types/Bookmark'
3
6
 
4
7
  export default (services: Services): RequestHandler => {
5
8
  return async (req, res, next) => {
@@ -11,12 +14,31 @@ export default (services: Services): RequestHandler => {
11
14
  export const populateRequestedReports = async (services: Services, req: Request, res: Response, next: NextFunction) => {
12
15
  if (res.locals.user) {
13
16
  const { uuid: userId } = res.locals.user
14
- res.locals.requestedReports = await services.requestedReportService.getAllReports(userId)
15
- res.locals.recentlyViewedReports = await services.recentlyViewedService.getAllReports(userId)
17
+ const { definitions, definitionsPath } = res.locals
18
+
19
+ const requested = await services.requestedReportService.getAllReports(userId)
20
+ res.locals.requestedReports = !definitionsPath
21
+ ? requested
22
+ : requested.filter((report: RequestedReport) => {
23
+ return DefinitionUtils.getCurrentVariantDefinition(definitions, report.reportId, report.id)
24
+ })
25
+
26
+ const recent = await services.recentlyViewedService.getAllReports(userId)
27
+ res.locals.recentlyViewedReports = !definitionsPath
28
+ ? recent
29
+ : recent.filter((report: StoredReportData) => {
30
+ return DefinitionUtils.getCurrentVariantDefinition(definitions, report.reportId, report.id)
31
+ })
16
32
 
17
33
  if (services.bookmarkService) {
18
34
  res.locals.bookmarkingEnabled = true
19
- res.locals.bookmarks = await services.bookmarkService.getAllBookmarks(userId)
35
+
36
+ const bookmarks = await services.bookmarkService.getAllBookmarks(userId)
37
+ res.locals.bookmarks = !definitionsPath
38
+ ? bookmarks
39
+ : bookmarks.filter((bookmark: BookmarkStoreData) => {
40
+ return DefinitionUtils.getCurrentVariantDefinition(definitions, bookmark.reportId, bookmark.id)
41
+ })
20
42
  }
21
43
 
22
44
  if (services.downloadPermissionService) {
@@ -1,6 +1,12 @@
1
1
  import ReportStoreService from './reportStoreService'
2
2
  import UserDataStore from '../data/reportDataStore'
3
- import { RequestStatus, RequestedReport, RecentlyViewedReport, ReportType } from '../types/UserReports'
3
+ import {
4
+ RequestStatus,
5
+ RequestedReport,
6
+ RecentlyViewedReport,
7
+ ReportType,
8
+ StoredReportData,
9
+ } from '../types/UserReports'
4
10
  import { ReportStoreConfig } from '../types/ReportStore'
5
11
  import logger from '../utils/logger'
6
12
 
@@ -10,7 +16,7 @@ export default class RecentlyViewedStoreService extends ReportStoreService {
10
16
  logger.info('Service created: RecentlyViewedStoreService')
11
17
  }
12
18
 
13
- async getAllReports(userId: string) {
19
+ async getAllReports(userId: string): Promise<StoredReportData[]> {
14
20
  const userConfig = await this.getState(userId)
15
21
  return userConfig.recentlyViewedReports
16
22
  }
@@ -34,7 +34,7 @@ export default class RequestedReportService extends ReportStoreService {
34
34
  return userConfig.requestedReports.find((report) => report.tableId === id)
35
35
  }
36
36
 
37
- async getAllReports(userId: string) {
37
+ async getAllReports(userId: string): Promise<RequestedReport[]> {
38
38
  const userConfig = await this.getState(userId)
39
39
  return userConfig.requestedReports
40
40
  }
@@ -1,7 +1,15 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const logger_1 = __importDefault(require("./logger"));
3
7
  exports.default = {
4
8
  getCurrentVariantDefinition: (definitions, reportId, variantId) => {
9
+ if (!definitions) {
10
+ logger_1.default.info('No definitions');
11
+ return undefined;
12
+ }
5
13
  let variantDef;
6
14
  const reportDef = definitions.find((report) => report.id === reportId);
7
15
  if (reportDef) {
@@ -1,7 +1,6 @@
1
- import { Request, Response } from 'express'
2
1
  import ReportingService from '../services/reportingService'
3
2
  import { components } from '../types/api'
4
- import localsHelper from './localsHelper'
3
+ import logger from './logger'
5
4
 
6
5
  export default {
7
6
  getCurrentVariantDefinition: (
@@ -9,6 +8,11 @@ export default {
9
8
  reportId: string,
10
9
  variantId: string,
11
10
  ): components['schemas']['VariantDefinition'] | undefined => {
11
+ if (!definitions) {
12
+ logger.info('No definitions')
13
+ return undefined
14
+ }
15
+
12
16
  let variantDef: components['schemas']['VariantDefinition']
13
17
  const reportDef = definitions.find(
14
18
  (report: components['schemas']['ReportDefinitionSummary']) => report.id === reportId,
@@ -50,8 +50,7 @@ const initFeatures = ({ router, config, services, features }) => {
50
50
  const initialisedFeatures = {};
51
51
  if (features !== undefined) {
52
52
  logger_1.default.info(`Embedded Reports: Features config found. Initialising features: ${features.list}`);
53
- const { config: featuresConfig, list } = features;
54
- const { userId } = featuresConfig;
53
+ const { list } = features;
55
54
  const { templatePath, layoutPath } = config;
56
55
  const downloadFeatureEnabled = list.includes(EmbeddedReportUtils_1.EmbeddedReportFeaturesList.download);
57
56
  const bookmarkFeatureEnabled = list.includes(EmbeddedReportUtils_1.EmbeddedReportFeaturesList.bookmark);
@@ -64,8 +64,7 @@ const initFeatures = ({ router, config, services, features }: EmbeddedSyncParams
64
64
  if (features !== undefined) {
65
65
  logger.info(`Embedded Reports: Features config found. Initialising features: ${features.list}`)
66
66
 
67
- const { config: featuresConfig, list } = features
68
- const { userId } = featuresConfig
67
+ const { list } = features
69
68
  const { templatePath, layoutPath } = config
70
69
 
71
70
  const downloadFeatureEnabled = list.includes(EmbeddedReportFeaturesList.download)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ministryofjustice/hmpps-digital-prison-reporting-frontend",
3
3
  "description": "The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.",
4
- "version": "4.2.1",
4
+ "version": "4.2.2",
5
5
  "main": "dpr/all.mjs",
6
6
  "sass": "dpr/all.scss",
7
7
  "engines": {
package/package.zip CHANGED
Binary file