generateur_v3/frontend/src/requests/room.request.ts

159 lines
3.6 KiB
TypeScript

import type { ExoSelect } from '../types/room.type';
import { roomInstance } from '../apis/room.api';
export const createRoom = (data: { name: string }, username: string | null = null) => {
return roomInstance
.request({
url: '/',
method: 'POST',
params: { username },
data: { ...data, public: false, global_results: false }
})
.then((r) => r.data);
};
export const getRoom = (id_code: string, clientId: string | null = null) => {
console.log('GETROOM', clientId, { ...(clientId != null && { clientId }) });
return roomInstance
.request({
url: '/' + id_code,
method: 'GET',
params: { ...(clientId != null && { clientId }) }
})
.then((r) => r.data);
};
export const createParcours = (
id_code: string,
parcours: { time: number; name: string; max_mistakes: number; exercices: {exercice_id: string, quantity:number}[] },
clientId: string | null = null
) => {
return roomInstance
.request({
url: `/${id_code}/parcours`,
method: 'POST',
params: { ...(clientId != null && { clientId }) },
data: parcours
})
.catch((r) => {
throw r.response.data;
})
.then((r) => r.data);
};
export const updateParcours = (
id_code: string,
parcours_id: string,
parcours: { time: number; name: string; max_mistakes: number; exercices: {exercice_id: string, quantity:number}[] },
clientId: string | null = null
) => {
return roomInstance
.request({
url: `/${id_code}/parcours/${parcours_id}`,
method: 'PUT',
params: { ...(clientId != null && { clientId }) },
data: parcours
})
.catch((r) => {
throw r.response.data;
})
.then((r) => r.data);
};
export const getParcours = (
id_code: string,
parcours_id: string,
clientId: string | null = null
) => {
return roomInstance
.request({
url: `/${id_code}/parcours/${parcours_id}`,
method: 'GET',
params: { ...(clientId != null && { clientId }) }
})
.catch((r) => {
throw r.response.data;
})
.then((r) => r.data);
};
export const challenge = (id_code: string, parcours_id: string, clientId: string | null = null) => {
return roomInstance
.request({
url: `/${id_code}/challenge/${parcours_id}`,
method: 'GET',
params: { ...(clientId != null && { clientId }) }
})
.catch((r) => {
throw r.response.data;
})
.then((r) => r.data);
};
export const sendChallenge = (
id_code: string,
parcours_id: string,
challenge_id: string,
data,
clientId: string | null = null
) => {
return roomInstance
.request({
url: `/${id_code}/challenge/${parcours_id}/${challenge_id}`,
method: 'POST',
params: { ...(clientId != null && { clientId }) },
data
})
.catch((r) => {
throw r.response.data;
})
.then((r) => r.data);
};
export const getChallenge = (
id_code: string,
challenge_id: string,
clientId: string | null = null
) => {
return roomInstance
.request({
url: `/${id_code}/correction/${challenge_id}`,
method: 'GET',
params: { ...(clientId != null && { clientId }) },
})
.catch((r) => {
throw r.response.data;
})
.then((r) => r.data);
};
export const corrigeChallenge = (
id_code: string,
challenge_id: string,
data,
clientId: string | null = null
) => {
return roomInstance
.request({
url: `/${id_code}/correction/${challenge_id}`,
method: 'PUT',
params: { ...(clientId != null && { clientId }) },
data
})
.catch((r) => {
throw r.response.data;
})
.then((r) => r.data);
};
export const delParcours = (
id_code: string,
parcours_id: string,
clientId: string | null = null
) => {
return roomInstance
.request({
url: `/${id_code}/parcours/${parcours_id}`,
method: 'DELETE',
params: { ...(clientId != null && { clientId }) }
})
.then((r) => r.data);
};