import type { Application, ApplicationWrite } from './dto/application' import { type HydraCollection, extractHydraMembers } from '~/utils/api' export function getApplications(): Promise { const api = useApi() return api.get('/applications', undefined, { toast: false, }).then((response) => { if (Array.isArray(response)) { return response } return extractHydraMembers(response as HydraCollection) }) } export function getApplication(slug: string): Promise { return useApi().get(`/applications/${slug}`, undefined, { toast: false, }) } export function createApplication(data: ApplicationWrite): Promise { return useApi().post('/applications', data, { toastSuccessKey: 'success.applications.create', toastErrorKey: 'errors.applications.create', }) } export function updateApplication(slug: string, data: Partial): Promise { return useApi().patch(`/applications/${slug}`, data, { toastSuccessKey: 'success.applications.update', toastErrorKey: 'errors.applications.update', }) } export function deleteApplication(slug: string): Promise { return useApi().delete(`/applications/${slug}`, undefined, { toastSuccessKey: 'success.applications.delete', toastErrorKey: 'errors.applications.delete', }) }