feat/ajout-de-fonctionnalites (#1)
All checks were successful
Auto Tag Develop / tag (push) Successful in 6s
All checks were successful
Auto Tag Develop / tag (push) Successful in 6s
Reviewed-on: #1 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
This commit was merged in pull request #1.
This commit is contained in:
41
frontend/services/applications.ts
Normal file
41
frontend/services/applications.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import type { Application, ApplicationWrite } from './dto/application'
|
||||
import { type HydraCollection, extractHydraMembers } from '~/utils/api'
|
||||
|
||||
export function getApplications(): Promise<Application[]> {
|
||||
const api = useApi()
|
||||
return api.get<Application[]>('/applications', undefined, {
|
||||
toast: false,
|
||||
}).then((response) => {
|
||||
if (Array.isArray(response)) {
|
||||
return response
|
||||
}
|
||||
return extractHydraMembers(response as HydraCollection<Application>)
|
||||
})
|
||||
}
|
||||
|
||||
export function getApplication(slug: string): Promise<Application> {
|
||||
return useApi().get<Application>(`/applications/${slug}`, undefined, {
|
||||
toast: false,
|
||||
})
|
||||
}
|
||||
|
||||
export function createApplication(data: ApplicationWrite): Promise<Application> {
|
||||
return useApi().post<Application>('/applications', data, {
|
||||
toastSuccessKey: 'success.applications.create',
|
||||
toastErrorKey: 'errors.applications.create',
|
||||
})
|
||||
}
|
||||
|
||||
export function updateApplication(slug: string, data: Partial<ApplicationWrite>): Promise<Application> {
|
||||
return useApi().patch<Application>(`/applications/${slug}`, data, {
|
||||
toastSuccessKey: 'success.applications.update',
|
||||
toastErrorKey: 'errors.applications.update',
|
||||
})
|
||||
}
|
||||
|
||||
export function deleteApplication(slug: string): Promise<void> {
|
||||
return useApi().delete<void>(`/applications/${slug}`, undefined, {
|
||||
toastSuccessKey: 'success.applications.delete',
|
||||
toastErrorKey: 'errors.applications.delete',
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user