@shinkashi/insight-sdk
Version:
Solution Insight SDK for JavaScript
56 lines (55 loc) • 2.36 kB
JavaScript
import { InsightRepository } from './repository';
export class DashboardRepository extends 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;
}
}