import { handleFetch, stringifyQuery } from './helpers'; import type { CrudStoreItemsModel } from '../stores/types/CrudStoreModel'; import { Translation } from '../stores/types/TranslationStoreModel'; import { SearchResponse } from '../types/api'; export const ITEMS_PER_PAGE = 50; export default class CrudApi { public static async getItemById(module: string, id: string): Promise { const response = await handleFetch(`/items/${module}/${id}`); return await response.json(); } public static async search(module: string, query?: string, language?: string, page?: number, sort?: string): Promise { const queryParams = { query: query || '', page: page || 1, itemsPerPage: ITEMS_PER_PAGE, language: language || '', sort: sort || '' }; const path = stringifyQuery(`/items/${module}/search`, queryParams); const response = await handleFetch(path); return await response.json(); } public static async getItemTranslations(module: string, id: string): Promise { const response = await handleFetch(`/items/translations/${module}/${id}`); return response.json(); } } export type CrudSearchReponse = SearchResponse;