@ministryofjustice/hmpps-digital-prison-reporting-frontend
Version:
The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.
77 lines (76 loc) • 2.9 kB
JavaScript
;
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 DashboardClient {
constructor(config) {
this.restClient = new restClient_1.default('Dashboard API Client', config);
}
getDefinition(token, dashboardId, dpdId, definitionsPath) {
this.logInfo('Get definition:', { dpdId, dashboardId });
const query = {
dataProductDefinitionsPath: definitionsPath,
};
return this.restClient
.get({
path: `/definitions/${dpdId}/dashboards/${dashboardId}`,
query,
token,
})
.then((response) => response);
}
requestAsyncDashboard(token, reportId, dashboardId, query) {
this.logInfo('Request dashboard:', { reportId, dashboardId });
return this.restClient
.get({
path: `/async/dashboards/${reportId}/${dashboardId}`,
token,
query,
})
.then((response) => response);
}
getAsyncDashboard(token, reportId, dashboardId, tableId, query) {
this.logInfo('Get dashboard:', { reportId, dashboardId, tableId });
return this.restClient
.get({
path: `/reports/${reportId}/dashboards/${dashboardId}/tables/${tableId}/result`,
token,
query,
})
.then((response) => response);
}
getAsyncStatus(token, reportId, dashboardId, executionId, dataProductDefinitionsPath, tableId) {
this.logInfo('Get status:', { reportId, dashboardId, executionId, tableId });
return this.restClient
.get({
path: `/reports/${reportId}/dashboards/${dashboardId}/statements/${executionId}/status`,
token,
query: {
dataProductDefinitionsPath,
tableId,
},
})
.then((response) => response);
}
cancelAsyncRequest(token, reportId, dashboardId, executionId, dataProductDefinitionsPath) {
this.logInfo('Cancel request:', { reportId, dashboardId, executionId });
return this.restClient
.delete({
path: `/reports/${reportId}/dashboards/${dashboardId}/statements/${executionId}`,
token,
query: {
dataProductDefinitionsPath,
},
})
.then((response) => response);
}
logInfo(title, args) {
logger_1.default.info(`Dashboard client: ${title}:`);
if (args && Object.keys(args).length)
logger_1.default.info(JSON.stringify(args, null, 2));
}
}
exports.default = DashboardClient;