Suppression de trains et défis

This commit is contained in:
2024-12-14 15:57:14 +01:00
parent cb1222d9cf
commit 3348979738
4 changed files with 177 additions and 11 deletions

View File

@ -81,6 +81,33 @@ export const useEndChallenge = ({ auth, onPostSuccess, onError }: ChallengeActio
})
}
export const useDeleteChallengeActionMutation = ({ auth, onPostSuccess, onError }: ChallengeActionProps) => {
return useMutation({
mutationFn: async (challengeActionId: number) => {
return fetch(`${process.env.EXPO_PUBLIC_TRAINTRAPE_MOI_SERVER}/challenge-actions/${challengeActionId}/`, {
method: "DELETE",
headers: {
"Authorization": `Bearer ${auth.token}`,
"Content-Type": "application/json",
},
})
},
onSuccess: async (resp) => {
if (resp.status >= 400) {
if (onError)
onError({ response: await resp.json() })
return
}
if (onPostSuccess)
onPostSuccess()
},
onError: async (error: Error) => {
if (onError)
onError({ error: error })
}
})
}
export const useAddChallengeMutation = ({ auth, onPostSuccess, onError }: ChallengeProps) => {
return useMutation({
mutationFn: async (challenge: Omit<Challenge, 'id'>) => {
@ -154,12 +181,12 @@ export const useDeleteChallengeMutation = ({ auth, onPostSuccess, onError }: Cha
"Authorization": `Bearer ${auth.token}`,
"Content-Type": "application/json",
},
}).then(resp => resp.json())
})
},
onSuccess: async (data) => {
if (data.statusCode) {
onSuccess: async (resp) => {
if (resp.status >= 400) {
if (onError)
onError({ response: data })
onError({ response: await resp.json() })
return
}
if (onPostSuccess)

View File

@ -103,7 +103,7 @@ export const useGameSwitchPlayerMutation = ({ auth, updateGameState, onPostSucce
})
}
export const useGameRepairMutation = ({ auth, onPostSuccess, onError }: GameProps) => {
export const useGameRepairMutation = ({ auth, onPostSuccess, onError }: Omit<GameProps, 'updateGameState'>) => {
return useMutation({
mutationFn: async () => {
return fetch(`${process.env.EXPO_PUBLIC_TRAINTRAPE_MOI_SERVER}/game/repair/`, {

View File

@ -47,3 +47,30 @@ export const useAddTrainMutation = ({ auth, onPostSuccess, onError }: TrainProps
}
})
}
export const useDeleteTrainMutation = ({ auth, onPostSuccess, onError }: TrainProps) => {
return useMutation({
mutationFn: async (trainId: string) => {
return fetch(`${process.env.EXPO_PUBLIC_TRAINTRAPE_MOI_SERVER}/trains/${trainId}/`, {
method: "DELETE",
headers: {
"Authorization": `Bearer ${auth.token}`,
"Content-Type": "application/json",
},
})
},
onSuccess: async (resp) => {
if (resp.status >= 400) {
if (onError)
onError({ response: await resp.json() })
return
}
if (onPostSuccess)
onPostSuccess()
},
onError: async (error: Error) => {
if (onError)
onError({ error: error })
}
})
}