@ministryofjustice/hmpps-digital-prison-reporting-frontend 3.26.4 → 3.26.6

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.
Files changed (32) hide show
  1. package/dpr/components/async-filters/utils.js +10 -7
  2. package/dpr/components/async-filters/utils.ts +10 -6
  3. package/dpr/components/async-polling/utils.js +7 -5
  4. package/dpr/components/async-polling/utils.ts +4 -2
  5. package/dpr/components/async-request-list/utils.js +10 -4
  6. package/dpr/components/async-request-list/utils.ts +7 -3
  7. package/dpr/components/recently-viewed-list/utils.js +3 -1
  8. package/dpr/components/recently-viewed-list/utils.ts +3 -1
  9. package/dpr/components/reports-list/utils.js +8 -6
  10. package/dpr/components/reports-list/utils.ts +48 -39
  11. package/dpr/routes/asyncReports.js +3 -1
  12. package/dpr/routes/asyncReports.ts +3 -1
  13. package/dpr/routes/bookmarks.js +6 -2
  14. package/dpr/routes/bookmarks.ts +4 -2
  15. package/dpr/routes/recentlyViewed.js +3 -1
  16. package/dpr/routes/recentlyViewed.ts +2 -1
  17. package/dpr/services/bookmarkService.js +19 -36
  18. package/dpr/services/bookmarkService.ts +19 -42
  19. package/dpr/services/recentlyViewedService.js +27 -70
  20. package/dpr/services/recentlyViewedService.ts +30 -81
  21. package/dpr/services/requestedReportsService.js +41 -73
  22. package/dpr/services/requestedReportsService.ts +44 -80
  23. package/dpr/services/userStoreService.js +7 -8
  24. package/dpr/services/userStoreService.ts +7 -12
  25. package/dpr/utils/bookmarkListUtils.js +21 -13
  26. package/dpr/utils/bookmarkListUtils.ts +25 -12
  27. package/dpr/utils/renderAsyncReport.js +9 -6
  28. package/dpr/utils/renderAsyncReport.ts +7 -5
  29. package/dpr/utils/reportsListHelper.js +5 -3
  30. package/dpr/utils/reportsListHelper.ts +5 -3
  31. package/package.json +1 -1
  32. package/package.zip +0 -0
@@ -188,6 +188,7 @@ const getFiltersFromDefinition = (definition) => {
188
188
  * Updates the store with the request details
189
189
  *
190
190
  * @param {Request} req
191
+ * @param {Response} res
191
192
  * @param {Services} services
192
193
  * @param {components['schemas']['FieldDefinition'][]} fields
193
194
  * @param {querySummaryResult} querySummaryData
@@ -195,22 +196,24 @@ const getFiltersFromDefinition = (definition) => {
195
196
  * @param {string} tableId
196
197
  * @return {*} {Promise<string>}
197
198
  */
198
- const updateStore = async (req, services, fields, querySummaryData, executionId, tableId) => {
199
+ const updateStore = async (req, res, services, fields, querySummaryData, executionId, tableId) => {
200
+ var _a;
199
201
  const { search, variantId } = req.body;
200
202
  const { query, filterData, querySummary, sortData } = querySummaryData;
203
+ const userId = ((_a = res.locals.user) === null || _a === void 0 ? void 0 : _a.uuid) ? res.locals.user.uuid : 'userId';
201
204
  // 1. check for duplicate requests and remove them from the request list
202
- const requestedReports = await services.asyncReportsStore.getAllReportsByVariantId(variantId);
203
- const viewedReports = await services.recentlyViewedStoreService.getAllReportsByVariantId(variantId);
205
+ const requestedReports = await services.asyncReportsStore.getAllReportsByVariantId(variantId, userId);
206
+ const viewedReports = await services.recentlyViewedStoreService.getAllReportsByVariantId(variantId, userId);
204
207
  const duplicateRequestIds = (0, reportSummaryHelper_1.getDuplicateRequestIds)(search, requestedReports);
205
208
  if (duplicateRequestIds.length) {
206
209
  await Promise.all(duplicateRequestIds.map(async (id) => {
207
- await await services.asyncReportsStore.removeReport(id);
210
+ await await services.asyncReportsStore.removeReport(id, userId);
208
211
  }));
209
212
  }
210
213
  const duplicateViewedReportIds = (0, reportSummaryHelper_1.getDuplicateRequestIds)(search, viewedReports);
211
214
  if (duplicateViewedReportIds.length) {
212
215
  await Promise.all(duplicateViewedReportIds.map(async (id) => {
213
- await await services.recentlyViewedStoreService.removeReport(id);
216
+ await await services.recentlyViewedStoreService.removeReport(id, userId);
214
217
  }));
215
218
  }
216
219
  // 2. Add the new request data to the store
@@ -218,7 +221,7 @@ const updateStore = async (req, services, fields, querySummaryData, executionId,
218
221
  ...req.body,
219
222
  executionId,
220
223
  tableId,
221
- }, filterData, sortData, query, querySummary);
224
+ }, filterData, sortData, query, querySummary, userId);
222
225
  return reportData.url.polling.pathname;
223
226
  };
224
227
  exports.updateStore = updateStore;
@@ -353,7 +356,7 @@ exports.default = {
353
356
  });
354
357
  let redirect = '';
355
358
  if (executionId && tableId) {
356
- redirect = await (0, exports.updateStore)(req, services, fields, querySummaryData, executionId, tableId);
359
+ redirect = await (0, exports.updateStore)(req, res, services, fields, querySummaryData, executionId, tableId);
357
360
  }
358
361
  return redirect;
359
362
  },
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-param-reassign */
2
- import { Request } from 'express'
2
+ import { Request, Response } from 'express'
3
3
  import moment from 'moment'
4
4
  import dayjs from 'dayjs'
5
5
  import isBetween from 'dayjs/plugin/isBetween'
@@ -204,6 +204,7 @@ const getFiltersFromDefinition = (definition: components['schemas']['VariantDefi
204
204
  * Updates the store with the request details
205
205
  *
206
206
  * @param {Request} req
207
+ * @param {Response} res
207
208
  * @param {Services} services
208
209
  * @param {components['schemas']['FieldDefinition'][]} fields
209
210
  * @param {querySummaryResult} querySummaryData
@@ -213,6 +214,7 @@ const getFiltersFromDefinition = (definition: components['schemas']['VariantDefi
213
214
  */
214
215
  export const updateStore = async (
215
216
  req: Request,
217
+ res: Response,
216
218
  services: Services,
217
219
  fields: components['schemas']['FieldDefinition'][],
218
220
  querySummaryData: querySummaryResult,
@@ -221,16 +223,17 @@ export const updateStore = async (
221
223
  ): Promise<string> => {
222
224
  const { search, variantId } = req.body
223
225
  const { query, filterData, querySummary, sortData } = querySummaryData
226
+ const userId = res.locals.user?.uuid ? res.locals.user.uuid : 'userId'
224
227
 
225
228
  // 1. check for duplicate requests and remove them from the request list
226
- const requestedReports = await services.asyncReportsStore.getAllReportsByVariantId(variantId)
227
- const viewedReports = await services.recentlyViewedStoreService.getAllReportsByVariantId(variantId)
229
+ const requestedReports = await services.asyncReportsStore.getAllReportsByVariantId(variantId, userId)
230
+ const viewedReports = await services.recentlyViewedStoreService.getAllReportsByVariantId(variantId, userId)
228
231
 
229
232
  const duplicateRequestIds = getDuplicateRequestIds(search, requestedReports)
230
233
  if (duplicateRequestIds.length) {
231
234
  await Promise.all(
232
235
  duplicateRequestIds.map(async (id: string) => {
233
- await await services.asyncReportsStore.removeReport(id)
236
+ await await services.asyncReportsStore.removeReport(id, userId)
234
237
  }),
235
238
  )
236
239
  }
@@ -239,7 +242,7 @@ export const updateStore = async (
239
242
  if (duplicateViewedReportIds.length) {
240
243
  await Promise.all(
241
244
  duplicateViewedReportIds.map(async (id: string) => {
242
- await await services.recentlyViewedStoreService.removeReport(id)
245
+ await await services.recentlyViewedStoreService.removeReport(id, userId)
243
246
  }),
244
247
  )
245
248
  }
@@ -255,6 +258,7 @@ export const updateStore = async (
255
258
  sortData,
256
259
  query,
257
260
  querySummary,
261
+ userId,
258
262
  )
259
263
 
260
264
  return reportData.url.polling.pathname
@@ -436,7 +440,7 @@ export default {
436
440
 
437
441
  let redirect = ''
438
442
  if (executionId && tableId) {
439
- redirect = await updateStore(req, services, fields, querySummaryData, executionId, tableId)
443
+ redirect = await updateStore(req, res, services, fields, querySummaryData, executionId, tableId)
440
444
  }
441
445
  return redirect
442
446
  },
@@ -3,20 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const AsyncReport_1 = require("../../types/AsyncReport");
4
4
  exports.default = {
5
5
  cancelRequest: async ({ req, res, services }) => {
6
- var _a;
6
+ var _a, _b;
7
7
  const token = ((_a = res.locals.user) === null || _a === void 0 ? void 0 : _a.token) ? res.locals.user.token : 'token';
8
+ const userId = ((_b = res.locals.user) === null || _b === void 0 ? void 0 : _b.uuid) ? res.locals.user.uuid : 'userId';
8
9
  const { reportId, variantId, executionId } = req.body;
9
10
  const response = await services.reportingService.cancelAsyncRequest(token, reportId, variantId, executionId);
10
11
  if (response && response.cancellationSucceeded) {
11
- await services.asyncReportsStore.updateStatus(executionId, AsyncReport_1.RequestStatus.ABORTED);
12
+ await services.asyncReportsStore.updateStatus(executionId, userId, AsyncReport_1.RequestStatus.ABORTED);
12
13
  }
13
14
  },
14
15
  renderPolling: async ({ req, res, services }) => {
15
- var _a;
16
+ var _a, _b;
16
17
  const csrfToken = res.locals.csrfToken || 'csrfToken';
18
+ const userId = ((_a = res.locals.user) === null || _a === void 0 ? void 0 : _a.uuid) ? res.locals.user.uuid : 'userId';
17
19
  const { dataProductDefinitionsPath: definitionPath } = req.query;
18
20
  const { reportId, variantId, executionId } = req.params;
19
- const reportData = await services.asyncReportsStore.getReportByExecutionId(executionId);
21
+ const reportData = await services.asyncReportsStore.getReportByExecutionId(executionId, userId);
20
22
  const { reportName, name, description, status, tableId, query, timestamp, url, errorMessage } = reportData;
21
23
  return {
22
24
  pollingRenderData: {
@@ -32,7 +34,7 @@ exports.default = {
32
34
  querySummary: query.summary,
33
35
  requestedAt: timestamp.requested,
34
36
  csrfToken,
35
- ...(((_a = url.report) === null || _a === void 0 ? void 0 : _a.fullUrl) && { reportUrl: url.report.fullUrl }),
37
+ ...(((_b = url.report) === null || _b === void 0 ? void 0 : _b.fullUrl) && { reportUrl: url.report.fullUrl }),
36
38
  ...(url.request.fullUrl && { requestUrl: url.request.fullUrl }),
37
39
  ...(errorMessage && { errorMessage }),
38
40
  },
@@ -4,20 +4,22 @@ import { AsyncReportUtilsParams } from '../../types/AsyncReportUtils'
4
4
  export default {
5
5
  cancelRequest: async ({ req, res, services }: AsyncReportUtilsParams) => {
6
6
  const token = res.locals.user?.token ? res.locals.user.token : 'token'
7
+ const userId = res.locals.user?.uuid ? res.locals.user.uuid : 'userId'
7
8
  const { reportId, variantId, executionId } = req.body
8
9
 
9
10
  const response = await services.reportingService.cancelAsyncRequest(token, reportId, variantId, executionId)
10
11
  if (response && response.cancellationSucceeded) {
11
- await services.asyncReportsStore.updateStatus(executionId, RequestStatus.ABORTED)
12
+ await services.asyncReportsStore.updateStatus(executionId, userId, RequestStatus.ABORTED)
12
13
  }
13
14
  },
14
15
 
15
16
  renderPolling: async ({ req, res, services }: AsyncReportUtilsParams) => {
16
17
  const csrfToken = (res.locals.csrfToken as unknown as string) || 'csrfToken'
18
+ const userId = res.locals.user?.uuid ? res.locals.user.uuid : 'userId'
17
19
  const { dataProductDefinitionsPath: definitionPath } = req.query
18
20
  const { reportId, variantId, executionId } = req.params
19
21
 
20
- const reportData = await services.asyncReportsStore.getReportByExecutionId(executionId)
22
+ const reportData = await services.asyncReportsStore.getReportByExecutionId(executionId, userId)
21
23
  const { reportName, name, description, status, tableId, query, timestamp, url, errorMessage } = reportData
22
24
 
23
25
  return {
@@ -98,24 +98,30 @@ const filterReports = (report) => {
98
98
  exports.filterReports = filterReports;
99
99
  exports.default = {
100
100
  getRequestStatus: async ({ req, res, services }) => {
101
+ var _a;
101
102
  const { executionId, status: currentStatus } = req.body;
103
+ const userId = ((_a = res.locals.user) === null || _a === void 0 ? void 0 : _a.uuid) ? res.locals.user.uuid : 'userId';
102
104
  const response = await (0, reportStatusHelper_1.getStatus)({ req, res, services });
103
105
  if (currentStatus !== response.status) {
104
- await services.asyncReportsStore.updateStatus(executionId, response.status, response.errorMessage);
105
- response.reportData = await services.asyncReportsStore.getReportByExecutionId(executionId);
106
+ await services.asyncReportsStore.updateStatus(executionId, userId, response.status, response.errorMessage);
107
+ response.reportData = await services.asyncReportsStore.getReportByExecutionId(executionId, userId);
106
108
  }
107
109
  return response;
108
110
  },
109
111
  getExpiredStatus: async ({ req, res, services }) => {
112
+ var _a;
113
+ const userId = ((_a = res.locals.user) === null || _a === void 0 ? void 0 : _a.uuid) ? res.locals.user.uuid : 'userId';
110
114
  const report = await (0, reportStatusHelper_1.getExpiredStatus)({ req, res, services });
111
115
  if (report.isExpired) {
112
- await services.asyncReportsStore.setToExpired(report.executionId);
116
+ await services.asyncReportsStore.setToExpired(report.executionId, userId);
113
117
  }
114
118
  return report.isExpired;
115
119
  },
116
120
  renderList: async ({ services, res, maxRows, }) => {
121
+ var _a;
117
122
  const csrfToken = res.locals.csrfToken || 'csrfToken';
118
- const requestedReportsData = await services.asyncReportsStore.getAllReports();
123
+ const userId = ((_a = res.locals.user) === null || _a === void 0 ? void 0 : _a.uuid) ? res.locals.user.uuid : 'userId';
124
+ const requestedReportsData = await services.asyncReportsStore.getAllReports(userId);
119
125
  let cardData = await ReportListHelper.formatCards(requestedReportsData, exports.filterReports, exports.formatCardData);
120
126
  if (maxRows)
121
127
  cardData = cardData.slice(0, maxRows);
@@ -89,24 +89,27 @@ export const filterReports = (report: AsyncReportData) => {
89
89
  export default {
90
90
  getRequestStatus: async ({ req, res, services }: AsyncReportUtilsParams) => {
91
91
  const { executionId, status: currentStatus } = req.body
92
+ const userId = res.locals.user?.uuid ? res.locals.user.uuid : 'userId'
92
93
  const response = await getStatus({ req, res, services })
93
94
 
94
95
  if (currentStatus !== response.status) {
95
96
  await services.asyncReportsStore.updateStatus(
96
97
  executionId,
98
+ userId,
97
99
  response.status as RequestStatus,
98
100
  response.errorMessage,
99
101
  )
100
- response.reportData = await services.asyncReportsStore.getReportByExecutionId(executionId)
102
+ response.reportData = await services.asyncReportsStore.getReportByExecutionId(executionId, userId)
101
103
  }
102
104
 
103
105
  return response
104
106
  },
105
107
 
106
108
  getExpiredStatus: async ({ req, res, services }: AsyncReportUtilsParams) => {
109
+ const userId = res.locals.user?.uuid ? res.locals.user.uuid : 'userId'
107
110
  const report = await getExpiredStatus({ req, res, services })
108
111
  if (report.isExpired) {
109
- await services.asyncReportsStore.setToExpired(report.executionId)
112
+ await services.asyncReportsStore.setToExpired(report.executionId, userId)
110
113
  }
111
114
  return report.isExpired
112
115
  },
@@ -117,7 +120,8 @@ export default {
117
120
  maxRows,
118
121
  }: { maxRows?: number } & AsyncReportUtilsParams): Promise<RenderTableListResponse> => {
119
122
  const csrfToken = (res.locals.csrfToken as unknown as string) || 'csrfToken'
120
- const requestedReportsData: AsyncReportData[] = await services.asyncReportsStore.getAllReports()
123
+ const userId = res.locals.user?.uuid ? res.locals.user.uuid : 'userId'
124
+ const requestedReportsData: AsyncReportData[] = await services.asyncReportsStore.getAllReports(userId)
121
125
 
122
126
  let cardData = await ReportListHelper.formatCards(requestedReportsData, filterReports, formatCardData)
123
127
  if (maxRows) cardData = cardData.slice(0, maxRows)
@@ -67,9 +67,11 @@ const filterReports = (report) => {
67
67
  exports.filterReports = filterReports;
68
68
  exports.default = {
69
69
  getExpiredStatus: async ({ req, res, services }) => {
70
+ var _a;
70
71
  const report = await (0, reportStatusHelper_1.getExpiredStatus)({ req, res, services });
72
+ const userId = ((_a = res.locals.user) === null || _a === void 0 ? void 0 : _a.uuid) ? res.locals.user.uuid : 'userId';
71
73
  if (report.isExpired) {
72
- await services.recentlyViewedStoreService.setToExpired(report.executionId);
74
+ await services.recentlyViewedStoreService.setToExpired(report.executionId, userId);
73
75
  }
74
76
  return report.isExpired;
75
77
  },
@@ -59,8 +59,10 @@ export const filterReports = (report: RecentlyViewedReportData) => {
59
59
  export default {
60
60
  getExpiredStatus: async ({ req, res, services }: AsyncReportUtilsParams) => {
61
61
  const report = await getExpiredStatus({ req, res, services })
62
+ const userId = res.locals.user?.uuid ? res.locals.user.uuid : 'userId'
63
+
62
64
  if (report.isExpired) {
63
- await services.recentlyViewedStoreService.setToExpired(report.executionId)
65
+ await services.recentlyViewedStoreService.setToExpired(report.executionId, userId)
64
66
  }
65
67
  return report.isExpired
66
68
  },
@@ -2,9 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const reportsListHelper_1 = require("../../utils/reportsListHelper");
4
4
  exports.default = {
5
- mapReportsList: (res, services) => {
5
+ mapReportsList: async (res, services) => {
6
+ var _a;
6
7
  const { definitions, csrfToken } = res.locals;
7
8
  const pathSuffix = res.locals.pathSuffix || '';
9
+ const userId = ((_a = res.locals.user) === null || _a === void 0 ? void 0 : _a.uuid) ? res.locals.user.uuid : 'userId';
8
10
  // Sort report Definitions by product name
9
11
  const sortedDefinitions = definitions.sort((a, b) => {
10
12
  if (a.name < b.name)
@@ -57,7 +59,7 @@ exports.default = {
57
59
  });
58
60
  return mergedArray;
59
61
  });
60
- const rows = sortedVariants.map((v) => {
62
+ const rows = await Promise.all(sortedVariants.map(async (v) => {
61
63
  const { id, name, description, reportName, reportId, reportDescription, type } = v;
62
64
  const desc = description || reportDescription;
63
65
  let hrefHtml;
@@ -65,9 +67,9 @@ exports.default = {
65
67
  let listType;
66
68
  switch (type) {
67
69
  case 'report':
68
- hrefHtml = `<a href="/async-reports/${reportId}/${id}/request${pathSuffix}">${name}</a>`;
70
+ hrefHtml = `<a href='/async-reports/${reportId}/${id}/request${pathSuffix}'>${name}</a>`;
69
71
  bookmarkColumn = {
70
- html: services.bookmarkService.createBookMarkToggleHtml(reportId, id, csrfToken, 'reports-list'),
72
+ html: await services.bookmarkService.createBookMarkToggleHtml(userId, reportId, id, csrfToken, 'reports-list'),
71
73
  attributes: {
72
74
  tabindex: 0,
73
75
  },
@@ -75,7 +77,7 @@ exports.default = {
75
77
  listType = (0, reportsListHelper_1.createTag)(type);
76
78
  break;
77
79
  case 'dashboard':
78
- hrefHtml = `<a href="/dashboards/${reportId}/load/${id}${pathSuffix}">${name}</a>`;
80
+ hrefHtml = `<a href='/dashboards/${reportId}/load/${id}${pathSuffix}'>${name}</a>`;
79
81
  bookmarkColumn = {};
80
82
  listType = (0, reportsListHelper_1.createTag)(type);
81
83
  break;
@@ -93,7 +95,7 @@ exports.default = {
93
95
  ...bookmarkColumn,
94
96
  },
95
97
  ];
96
- });
98
+ }));
97
99
  const head = [
98
100
  { text: 'Product', classes: 'dpr-product-head' },
99
101
  { text: 'Name', classes: 'dpr-name-head' },
@@ -15,12 +15,13 @@ interface definitionData {
15
15
  }
16
16
 
17
17
  export default {
18
- mapReportsList: (
18
+ mapReportsList: async (
19
19
  res: Response,
20
20
  services: Services,
21
- ): { head: { text: string }[]; rows: { text?: string; html?: string }[] } => {
21
+ ): Promise<{ head: { text: string }[]; rows: { text?: string; html?: string }[] }> => {
22
22
  const { definitions, csrfToken } = res.locals
23
23
  const pathSuffix = res.locals.pathSuffix || ''
24
+ const userId = res.locals.user?.uuid ? res.locals.user.uuid : 'userId'
24
25
 
25
26
  // Sort report Definitions by product name
26
27
  const sortedDefinitions = definitions.sort(
@@ -80,45 +81,53 @@ export default {
80
81
  },
81
82
  )
82
83
 
83
- const rows = sortedVariants.map((v: definitionData) => {
84
- const { id, name, description, reportName, reportId, reportDescription, type } = v
85
- const desc = description || reportDescription
84
+ const rows = await Promise.all(
85
+ sortedVariants.map(async (v: definitionData) => {
86
+ const { id, name, description, reportName, reportId, reportDescription, type } = v
87
+ const desc = description || reportDescription
86
88
 
87
- let hrefHtml
88
- let bookmarkColumn
89
- let listType
90
- switch (type) {
91
- case 'report':
92
- hrefHtml = `<a href="/async-reports/${reportId}/${id}/request${pathSuffix}">${name}</a>`
93
- bookmarkColumn = {
94
- html: services.bookmarkService.createBookMarkToggleHtml(reportId, id, csrfToken, 'reports-list'),
95
- attributes: {
96
- tabindex: 0,
97
- },
98
- }
99
- listType = createTag(type)
100
- break
101
- case 'dashboard':
102
- hrefHtml = `<a href="/dashboards/${reportId}/load/${id}${pathSuffix}">${name}</a>`
103
- bookmarkColumn = {}
104
- listType = createTag(type)
105
- break
106
- default:
107
- hrefHtml = ''
108
- bookmarkColumn = {}
109
- break
110
- }
89
+ let hrefHtml
90
+ let bookmarkColumn
91
+ let listType
92
+ switch (type) {
93
+ case 'report':
94
+ hrefHtml = `<a href='/async-reports/${reportId}/${id}/request${pathSuffix}'>${name}</a>`
95
+ bookmarkColumn = {
96
+ html: await services.bookmarkService.createBookMarkToggleHtml(
97
+ userId,
98
+ reportId,
99
+ id,
100
+ csrfToken,
101
+ 'reports-list',
102
+ ),
103
+ attributes: {
104
+ tabindex: 0,
105
+ },
106
+ }
107
+ listType = createTag(type)
108
+ break
109
+ case 'dashboard':
110
+ hrefHtml = `<a href='/dashboards/${reportId}/load/${id}${pathSuffix}'>${name}</a>`
111
+ bookmarkColumn = {}
112
+ listType = createTag(type)
113
+ break
114
+ default:
115
+ hrefHtml = ''
116
+ bookmarkColumn = {}
117
+ break
118
+ }
111
119
 
112
- return [
113
- { text: reportName },
114
- { html: hrefHtml },
115
- { html: createShowMoreHtml(desc) },
116
- { html: listType },
117
- {
118
- ...bookmarkColumn,
119
- },
120
- ]
121
- })
120
+ return [
121
+ { text: reportName },
122
+ { html: hrefHtml },
123
+ { html: createShowMoreHtml(desc) },
124
+ { html: listType },
125
+ {
126
+ ...bookmarkColumn,
127
+ },
128
+ ]
129
+ }),
130
+ )
122
131
 
123
132
  const head = [
124
133
  { text: 'Product', classes: 'dpr-product-head' },
@@ -111,8 +111,10 @@ function routes({ router, services, layoutPath, templatePath = 'dpr/views/', })
111
111
  }
112
112
  };
113
113
  const removeRequestedItemHandler = async (req, res, next) => {
114
+ var _a;
115
+ const userId = ((_a = res.locals.user) === null || _a === void 0 ? void 0 : _a.uuid) ? res.locals.user.uuid : 'userId';
114
116
  try {
115
- await services.asyncReportsStore.removeReport(req.body.executionId);
117
+ await services.asyncReportsStore.removeReport(req.body.executionId, userId);
116
118
  res.end();
117
119
  }
118
120
  catch (error) {
@@ -99,8 +99,10 @@ export default function routes({
99
99
  }
100
100
 
101
101
  const removeRequestedItemHandler: RequestHandler = async (req, res, next) => {
102
+ const userId = res.locals.user?.uuid ? res.locals.user.uuid : 'userId'
103
+
102
104
  try {
103
- await services.asyncReportsStore.removeReport(req.body.executionId)
105
+ await services.asyncReportsStore.removeReport(req.body.executionId, userId)
104
106
  res.end()
105
107
  } catch (error) {
106
108
  req.body.title = 'Failed to abort request'
@@ -7,12 +7,16 @@ exports.default = routes;
7
7
  const bookmarkListUtils_1 = __importDefault(require("../utils/bookmarkListUtils"));
8
8
  function routes({ router, services, layoutPath, templatePath = 'dpr/views/', }) {
9
9
  router.post('/addBookmark/', async (req, res) => {
10
+ var _a;
11
+ const userId = ((_a = res.locals.user) === null || _a === void 0 ? void 0 : _a.uuid) ? res.locals.user.uuid : 'userId';
10
12
  const { reportId, variantId } = req.body;
11
- await services.bookmarkService.addBookmark(reportId, variantId);
13
+ await services.bookmarkService.addBookmark(userId, reportId, variantId);
12
14
  res.end();
13
15
  });
14
16
  router.post('/removeBookmark/', async (req, res) => {
15
- await services.bookmarkService.removeBookmark(req.body.variantId);
17
+ var _a;
18
+ const userId = ((_a = res.locals.user) === null || _a === void 0 ? void 0 : _a.uuid) ? res.locals.user.uuid : 'userId';
19
+ await services.bookmarkService.removeBookmark(userId, req.body.variantId);
16
20
  res.end();
17
21
  });
18
22
  router.get('/async-reports/bookmarks', async (req, res) => {
@@ -14,13 +14,15 @@ export default function routes({
14
14
  templatePath?: string
15
15
  }) {
16
16
  router.post('/addBookmark/', async (req, res) => {
17
+ const userId = res.locals.user?.uuid ? res.locals.user.uuid : 'userId'
17
18
  const { reportId, variantId } = req.body
18
- await services.bookmarkService.addBookmark(reportId, variantId)
19
+ await services.bookmarkService.addBookmark(userId, reportId, variantId)
19
20
  res.end()
20
21
  })
21
22
 
22
23
  router.post('/removeBookmark/', async (req, res) => {
23
- await services.bookmarkService.removeBookmark(req.body.variantId)
24
+ const userId = res.locals.user?.uuid ? res.locals.user.uuid : 'userId'
25
+ await services.bookmarkService.removeBookmark(userId, req.body.variantId)
24
26
  res.end()
25
27
  })
26
28
 
@@ -16,7 +16,9 @@ function routes({ router, services, layoutPath, templatePath = 'dpr/views/', })
16
16
  }
17
17
  };
18
18
  const removeViewedItemHandler = async (req, res, next) => {
19
- await services.recentlyViewedStoreService.removeReport(req.body.executionId);
19
+ var _a;
20
+ const userId = ((_a = res.locals.user) === null || _a === void 0 ? void 0 : _a.uuid) ? res.locals.user.uuid : 'userId';
21
+ await services.recentlyViewedStoreService.removeReport(req.body.executionId, userId);
20
22
  res.end();
21
23
  };
22
24
  router.get('/async-reports/recently-viewed', async (req, res) => {
@@ -23,7 +23,8 @@ export default function routes({
23
23
  }
24
24
 
25
25
  const removeViewedItemHandler: RequestHandler = async (req, res, next) => {
26
- await services.recentlyViewedStoreService.removeReport(req.body.executionId)
26
+ const userId = res.locals.user?.uuid ? res.locals.user.uuid : 'userId'
27
+ await services.recentlyViewedStoreService.removeReport(req.body.executionId, userId)
27
28
  res.end()
28
29
  }
29
30
 
@@ -7,49 +7,32 @@ const userStoreService_1 = __importDefault(require("./userStoreService"));
7
7
  class BookmarkService extends userStoreService_1.default {
8
8
  constructor(userDataStore) {
9
9
  super(userDataStore);
10
- this.isBookmarked = (variantId) => {
11
- return this.bookmarks.filter((bookmark) => bookmark.variantId === variantId).length > 0;
10
+ this.isBookmarked = async (variantId, userId) => {
11
+ const userConfig = await this.getState(userId);
12
+ return userConfig.bookmarks.some((bookmark) => bookmark.variantId === variantId);
12
13
  };
13
14
  }
14
- async getBookmarkState() {
15
- await this.getState();
16
- this.bookmarks = this.userConfig.bookmarks;
15
+ async getAllBookmarks(userId) {
16
+ const userConfig = await this.getState(userId);
17
+ return userConfig.bookmarks;
17
18
  }
18
- async saveBookmarkState() {
19
- this.userConfig.bookmarks = this.bookmarks;
20
- await this.saveState();
19
+ async addBookmark(userId, reportId, variantId) {
20
+ const userConfig = await this.getState(userId);
21
+ if (!userConfig.bookmarks.some((bookmark) => bookmark.variantId === variantId))
22
+ userConfig.bookmarks.unshift({ reportId, variantId });
23
+ await this.saveState(userId, userConfig);
21
24
  }
22
- async getBookmark(id) {
23
- await this.getBookmarkState();
24
- return this.bookmarks.find((report) => report.variantId === id);
25
- }
26
- async getAllBookmarks() {
27
- await this.getBookmarkState();
28
- return this.bookmarks;
29
- }
30
- async addBookmark(reportId, variantId) {
31
- await this.getBookmarkState();
32
- if (!this.isBookmarked(variantId))
33
- this.bookmarks.unshift({ reportId, variantId });
34
- await this.saveBookmarkState();
35
- }
36
- async removeBookmark(variantId) {
37
- await this.getBookmarkState();
38
- const index = this.bookmarks.findIndex((bookmark) => bookmark.variantId === variantId);
25
+ async removeBookmark(userId, variantId) {
26
+ const userConfig = await this.getState(userId);
27
+ const index = userConfig.bookmarks.findIndex((bookmark) => bookmark.variantId === variantId);
39
28
  if (index >= 0) {
40
- this.bookmarks.splice(index, 1);
41
- }
42
- await this.saveBookmarkState();
43
- }
44
- async bumpBookmark(reportId, variantId) {
45
- await this.getBookmarkState();
46
- if (this.isBookmarked(variantId)) {
47
- await this.removeBookmark(variantId);
48
- await this.addBookmark(reportId, variantId);
29
+ userConfig.bookmarks.splice(index, 1);
49
30
  }
31
+ await this.saveState(userId, userConfig);
50
32
  }
51
- createBookMarkToggleHtml(reportId, variantId, csrfToken, id) {
52
- const checked = this.isBookmarked(variantId) ? 'checked' : null;
33
+ async createBookMarkToggleHtml(userId, reportId, variantId, csrfToken, id) {
34
+ const userConfig = await this.getState(userId);
35
+ const checked = userConfig.bookmarks.some((bookmark) => bookmark.variantId === variantId) ? 'checked' : null;
53
36
  const tooltip = !checked ? 'Add Bookmark' : 'Remove Bookmark';
54
37
  return `<div class='dpr-bookmark dpr-bookmark-tooltip dpr-bookmark-table' tooltip="${tooltip}" data-dpr-module="bookmark-toggle">
55
38
  <input class="bookmark-input" aria-label="bookmark toggle" type='checkbox' id='${reportId}-${variantId}-${id}' data-report-id='${reportId}' data-variant-id='${variantId}' data-csrf-token='${csrfToken}' ${checked} />