📦 EqualifyEverything / equalify-dashboard

📄 filters.ts · 45 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45import { get } from 'aws-amplify/api';

interface ApiResponse<T> {
  status: string;
  result: T;
  total?: number;
}

export interface FilterOption {
  value: string;
  label: string;
  type: string;
}

export interface FiltersResponse {
  messages: FilterOption[];
  tags: FilterOption[];
  properties: FilterOption[];
  urls: FilterOption[];
  statuses: FilterOption[];
}

const API_NAME = 'auth';

/**
 * Fetch filters for reports
 * @returns {Promise<FiltersResponse>} Filters for reports
 * @throws Will throw an error if the fetch fails
 */
export const getFilters = async (): Promise<FiltersResponse> => {
  try {
    const response = await get({
      apiName: API_NAME,
      path: '/get/filters',
    }).response;

    const { body } = response;
    const { result } = (await body.json()) as unknown as ApiResponse<FiltersResponse>;
    return result;
  } catch (error) {
    console.error('Error fetching filters', error);
    throw error;
  }
};