@shinkashi/insight-sdk
Version:
Solution Insight SDK for JavaScript
60 lines (59 loc) • 2.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DashboardRepository = void 0;
const repository_1 = require("./repository");
class DashboardRepository extends repository_1.InsightRepository {
async favourite(id) {
const response = await this.client.ax.post(this.objPath + '/' + id + '/favourite');
if (response.status !== 200) {
throw new Error(`API Error ${response.status}: ${response.data}`);
}
return response.data;
}
async unfavourite(id) {
const response = await this.client.ax.post(this.objPath + '/' + id + '/unfavourite');
if (response.status !== 200) {
throw new Error(`API Error ${response.status}: ${response.data}`);
}
return response.data;
}
async addWidget(dashboardId, widget) {
const response = await this.client.ax.post(`${this.objPath}/${dashboardId}/widgets`, widget);
if (response.status !== 201) {
throw new Error(`API Error ${response.status}: ${response.data}`);
}
return response.data;
}
async deleteWidget(dashboardId, widgetId) {
const response = await this.client.ax.delete(`${this.objPath}/${dashboardId}/widgets/${widgetId}`);
if (!([200, 204].includes(response.status))) {
throw new Error(`API Error ${response.status}: ${response.data}`);
}
return response.data;
}
async rearrangeWidgets(dashboardId, widgetList) {
const response = await this.client.ax.patch(`${this.objPath}/${dashboardId}/widgets`, widgetList);
if (response.status !== 200) {
throw new Error(`API Error ${response.status}: ${response.data}`);
}
return response.data;
}
async updateWidgetSettings(dashboardId, widgetId, body) {
const response = await this.client.ax.patch(`${this.objPath}/${dashboardId}/widgets/${widgetId}`, body);
if (response.status !== 200) {
throw new Error(`API Error ${response.status}: ${response.data}`);
}
return response.data;
}
async delete(id) {
if (id === '') {
throw new Error('id cannot be empty');
}
const response = await this.client.ax.delete(this.objPath + '/' + id);
if (!([200, 204].includes(response.status))) {
throw new Error(`API Error ${response.status}: ${response.data}`);
}
return response.data;
}
}
exports.DashboardRepository = DashboardRepository;