Request get exos

This commit is contained in:
Kilton937342 2022-06-24 19:51:47 +02:00
parent bf62ac718b
commit 58646f7cd9
2 changed files with 9 additions and 3 deletions

View File

@ -70,7 +70,11 @@ class ExerciceAPI(APIView):
userExosListSorted = userExos userExosListSorted = userExos
if code != 'all' and code != 'pdf' and code != "web": if code != 'all' and code != 'pdf' and code != "web":
exo = Exercice.objects.get(id_code=code) try:
exo = Exercice.objects.get(id_code=code)
except:
exo = None
return Response({'error': "Not found"}, status= status.HTTP_404_NOT_FOUND)
isUser = False isUser = False
if request.user == exo.author: if request.user == exo.author:
isUser = True isUser = True

View File

@ -29,14 +29,16 @@ export default function ModalCard({ step, onClose, onDelete, tags, queryKey }) {
const alert = useAlert(); const alert = useAlert();
const [edit, setEdit] = useState(false); const [edit, setEdit] = useState(false);
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const { const {
isLoading: isUpdating, isLoading: isUpdating,
isFetching, isFetching,
data: step_data, data: step_data,
} = useQuery( } = useQuery(
["exo-data", step.id_code], ["exo-data", step.id_code],
async () => await getExos(step.id_code), async () => await getExos(step.id_code).catch(() => {
notificationService.error('Erreur', "Exercice introuvable")
}),
{ initialData: step, refetchOnWindowFocus: !edit } { initialData: step, refetchOnWindowFocus: !edit }
); );
const [selected, setSelected] = useState([]); const [selected, setSelected] = useState([]);