feat(central) : ajoute le pilotage de maintenance et le deploiement prod
This commit is contained in:
10
frontend/services/dto/managed-application.ts
Normal file
10
frontend/services/dto/managed-application.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export type ManagedApplication = {
|
||||
slug: string
|
||||
name: string
|
||||
maintenance: boolean
|
||||
}
|
||||
|
||||
export type ManagedApplicationCollection = {
|
||||
'hydra:member'?: ManagedApplication[]
|
||||
member?: ManagedApplication[]
|
||||
}
|
||||
33
frontend/services/managed-applications.ts
Normal file
33
frontend/services/managed-applications.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import type { ManagedApplication, ManagedApplicationCollection } from './dto/managed-application'
|
||||
|
||||
function normalizeManagedApplications(response: ManagedApplication[] | ManagedApplicationCollection): ManagedApplication[] {
|
||||
if (Array.isArray(response)) {
|
||||
return response
|
||||
}
|
||||
|
||||
return response['hydra:member'] ?? response.member ?? []
|
||||
}
|
||||
|
||||
export async function getManagedApplications(): Promise<ManagedApplication[]> {
|
||||
const api = useApi()
|
||||
const response = await api.get<ManagedApplication[] | ManagedApplicationCollection>('/applications')
|
||||
|
||||
return normalizeManagedApplications(response)
|
||||
}
|
||||
|
||||
export function setApplicationMaintenance(slug: string, maintenance: boolean) {
|
||||
const api = useApi()
|
||||
|
||||
return api.post<ManagedApplication>(
|
||||
`/applications/${slug}/maintenance`,
|
||||
{ maintenance },
|
||||
{
|
||||
toastSuccessKey: maintenance
|
||||
? 'success.applications.activateMaintenance'
|
||||
: 'success.applications.deactivateMaintenance',
|
||||
toastErrorKey: maintenance
|
||||
? 'errors.applications.activateMaintenance'
|
||||
: 'errors.applications.deactivateMaintenance'
|
||||
}
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user