Skip to content

PostgreSQL backup tool with Point-In-Time-Recovery and restore verification

2.2 KB
Raw Blame
import { getApplicationServer } from '../../../constants';
import { apiHelper } from '../../../shared/api/apiHelper';
import RequestOptions from '../../../shared/api/RequestOptions';
import type { Notifier } from '../models/Notifier';

export const notifierApi = {
  async saveNotifier(notifier: Notifier) {
    const requestOptions: RequestOptions = new RequestOptions();
    requestOptions.setBody(JSON.stringify(notifier));
    return apiHelper.fetchPostJson<Notifier>(
      `${getApplicationServer()}/api/v1/notifiers`,
      requestOptions,
    );
  },

  async getNotifier(id: string) {
    const requestOptions: RequestOptions = new RequestOptions();
    return apiHelper.fetchGetJson<Notifier>(
      `${getApplicationServer()}/api/v1/notifiers/${id}`,
      requestOptions,
      true,
    );
  },

  async getNotifiers(workspaceId: string) {
    const requestOptions: RequestOptions = new RequestOptions();
    return apiHelper.fetchGetJson<Notifier[]>(
      `${getApplicationServer()}/api/v1/notifiers?workspace_id=${workspaceId}`,
      requestOptions,
      true,
    );
  },

  async deleteNotifier(id: string) {
    const requestOptions: RequestOptions = new RequestOptions();
    return apiHelper.fetchDeleteJson(
      `${getApplicationServer()}/api/v1/notifiers/${id}`,
      requestOptions,
    );
  },

  async sendTestNotification(id: string) {
    const requestOptions: RequestOptions = new RequestOptions();
    return apiHelper.fetchPostJson(
      `${getApplicationServer()}/api/v1/notifiers/${id}/test`,
      requestOptions,
    );
  },

  async sendTestNotificationDirect(notifier: Notifier) {
    const requestOptions: RequestOptions = new RequestOptions();
    requestOptions.setBody(JSON.stringify(notifier));
    return apiHelper.fetchPostJson(
      `${getApplicationServer()}/api/v1/notifiers/direct-test`,
      requestOptions,
    );
  },

  async transferNotifier(notifierId: string, targetWorkspaceId: string) {
    const requestOptions: RequestOptions = new RequestOptions();
    requestOptions.setBody(JSON.stringify({ targetWorkspaceId }));
    return apiHelper.fetchPostJson(
      `${getApplicationServer()}/api/v1/notifiers/${notifierId}/transfer`,
      requestOptions,
    );
  },
};