@ministryofjustice/hmpps-digital-prison-reporting-frontend
Version:
The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.
87 lines (84 loc) • 3.07 kB
JavaScript
import logger from '../utils/logger.js';
import { RestClient } from './restClient.js';
class DashboardClient {
restClient;
constructor(config) {
this.restClient = new RestClient('Dashboard API Client', config);
}
getDefinition(token, dashboardId, dpdId, definitionsPath, queryData) {
const query = {
...queryData,
dataProductDefinitionsPath: definitionsPath,
};
this.logInfo('Get definition:', { dpdId, dashboardId, ...query });
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, tableId, dataProductDefinitionsPath) {
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);
}
getSyncDashboard(token, reportId, dashboardId, query) {
this.logInfo('Get dashboard:', { reportId, dashboardId });
return this.restClient
.get({
path: `/reports/${reportId}/dashboards/${dashboardId}`,
token,
query,
})
.then(response => response);
}
logInfo(title, args) {
logger.info(`Dashboard client: ${title}:`);
if (args && Object.keys(args).length)
logger.info(JSON.stringify(args));
}
}
export { DashboardClient, DashboardClient as default };
//# sourceMappingURL=dashboardClient.js.map