UNPKG

@ministryofjustice/hmpps-digital-prison-reporting-frontend

Version:

The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.

167 lines (166 loc) 6.11 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const logger_1 = __importDefault(require("../utils/logger")); const restClient_1 = __importDefault(require("./restClient")); class ReportingClient { constructor(config) { this.restClient = new restClient_1.default('Reporting API Client', config); } getCount(resourceName, token, countRequest) { logger_1.default.info(`Reporting client: Get count. { resourceName: ${resourceName} }`); return this.restClient .get({ path: `/${resourceName}/count`, query: countRequest.toRecordWithFilterPrefix(true), token, }) .then((response) => response.count); } getList(resourceName, token, listRequest) { return this.getListWithWarnings(resourceName, token, listRequest).then((response) => response.data); } getListWithWarnings(resourceName, token, listRequest) { logger_1.default.info(`Reporting client: Get list. { resourceName: ${resourceName} }`); return this.restClient .getWithHeaders({ path: `/${resourceName}`, query: listRequest.toRecordWithFilterPrefix(true), token, }) .then((response) => ({ data: response.data, warnings: { noDataAvailable: response.headers['x-no-data-warning'], }, })); } getDefinitions(token, definitionsPath) { this.logInfo('Get definitions'); const params = { query: { renderMethod: 'HTML', dataProductDefinitionsPath: definitionsPath, }, }; return this.restClient .get({ path: '/definitions', query: params.query, token, }) .then((response) => response); } getDefinition(token, reportId, variantId, definitionsPath) { const query = { dataProductDefinitionsPath: definitionsPath, }; this.logInfo('Get definition', { reportId, variantId }); return this.restClient .get({ path: `/definitions/${reportId}/${variantId}`, query, token, }) .then((response) => response); } getFieldValues({ token, definitionName, variantName, fieldName, prefix, definitionsPath, }) { const query = { dataProductDefinitionsPath: definitionsPath, prefix, }; this.logInfo('Get field values', { definitionName, variantName, fieldName, prefix }); return this.restClient .get({ path: `/reports/${definitionName}/${variantName}/${fieldName}`, token, query, }) .then((response) => response); } requestAsyncReport(token, reportId, variantId, query) { this.logInfo('Request report', { reportId, variantId }); return this.restClient .get({ path: `/async/reports/${reportId}/${variantId}`, token, query, }) .then((response) => response); } cancelAsyncRequest(token, reportId, variantId, executionId, dataProductDefinitionsPath) { this.logInfo('Cancel Request', { reportId, variantId, executionId }); return this.restClient .delete({ path: `/reports/${reportId}/${variantId}/statements/${executionId}`, token, query: { dataProductDefinitionsPath, }, }) .then((response) => response); } getAsyncReport(token, reportId, variantId, tableId, query) { this.logInfo('Get Data', { reportId, variantId, tableId }); return this.restClient .get({ path: `/reports/${reportId}/${variantId}/tables/${tableId}/result`, token, query, }) .then((response) => response); } getAsyncSummaryReport(token, reportId, variantId, tableId, summaryId, query) { this.logInfo('Get summary data', { reportId, variantId, tableId, summaryId }); return this.restClient .get({ path: `/reports/${reportId}/${variantId}/tables/${tableId}/result/summary/${summaryId}`, token, query, }) .then((response) => response); } getAsyncReportStatus(token, reportId, variantId, executionId, dataProductDefinitionsPath, tableId) { this.logInfo('Get status', { reportId, variantId, tableId, executionId }); return this.restClient .get({ path: `/reports/${reportId}/${variantId}/statements/${executionId}/status`, token, query: { dataProductDefinitionsPath, tableId, }, }) .then((response) => response); } getAsyncCount(token, tableId, dataProductDefinitionsPath) { this.logInfo('Get count', { tableId }); return this.restClient .get({ path: `/report/tables/${tableId}/count`, token, query: { dataProductDefinitionsPath, }, }) .then((response) => response.count); } getAsyncInteractiveCount(token, tableId, reportId, id, filters) { this.logInfo('Get interactive count', { tableId, reportId, id }); return this.restClient .get({ path: `/reports/${reportId}/${id}/tables/${tableId}/count`, token, query: filters.toRecordWithFilterPrefix(true), }) .then((response) => response.count); } logInfo(title, args) { logger_1.default.info(`Reporting Client: ${title}:`); if (args && Object.keys(args).length) logger_1.default.info(JSON.stringify(args, null, 2)); } } exports.default = ReportingClient;