import { roomInstance } from "../apis/roomInstance.intance.js"; import { isBrowser } from "../utils/utils.js"; export const createRoom = async (data) => { return await roomInstance .request({ method: "POST", url: "room/", data: { ...data }, headers: { Authorization: isBrowser ? localStorage.getItem("token") !== null ? `Token ${localStorage.getItem("token")}` : null: null }, }) .then((res) => res.data.data); }; export const deleteRoom = async (data) => { return await roomInstance .request({ method: "DELETE", url: "room/", data: { ...data }, headers: { Authorization: isBrowser ? localStorage.getItem("token") !== null ? `Token ${localStorage.getItem("token")}` : null: null }, }) .then((res) => res.data.data); }; export const joinRoom = async (data) => { return await roomInstance .request({ method: "PATCH", url: "room/", data: {...data} }) .then((res) => res.data.data); }; export const getRoom = async (code, clientId) => { return await roomInstance .request({ method: "GET", url: "room/", params: { code: code, clientId: clientId }, }) .then((res) => res.data.data) .catch((err) => { throw err; });; }; export const checkRoom = async (code, clientId) => { return await roomInstance .request({ method: "GET", url: "room/" + code, params: {clientId} }) .then((res) => res.data.data) .catch((err) => { throw err; });; }; export const delRoom = async (code) => { return await roomInstance .request({ method: "DELETE", url: "room/", data: { code: code }, }) .then((res) => res.data.data) .catch((err) => { throw err; });; }; export const createParcours = async (data) => { return await roomInstance .request({ method: "POST", url: "parcours/", data: { ...data }, }) .then((res) => res.data.data) .catch((err) => { throw err; }); }; export const editParcours = async (data) => { return await roomInstance .request({ method: "PUT", url: "parcours/", data: { ...data }, }) .then((res) => res.data.data) .catch((err) => { throw err; }); }; export const getParcoursChallenge = async (id_code, user_code) => { return await roomInstance .request({ method: "GET", url: "challenge/", params: { code: id_code, user_code: user_code }, }) .then((res) => res.data.data) .catch((err) => { throw err; }); }; export const getParcoursInfos = async (id_code, user_code) => { return await roomInstance .request({ method: "GET", url: "parcours/", params: { code: id_code, user_code: user_code }, }) .then((res) => res.data.data) .catch((err) => { throw err; }); }; export const getEditParcoursInfos = async (id_code) => { return await roomInstance .request({ method: "GET", url: "edit/", params: { id_code: id_code}, }) .then((res) => res.data.data) .catch((err) => { throw err; }); }; export const getEditRoomInfos = async (id_code) => { return await roomInstance .request({ method: "GET", url: "room_edit/", params: { id_code: id_code }, }) .then((res) => res.data.data) .catch((err) => { throw err; }); }; export const challengeParcours = async (data) => { return await roomInstance .request({ method: "POST", url: "challenge/", data: {...data }, }) .then((res) => res.data.data) .catch((err) => { throw err; }); }; export const correctParcours = async (data) => { return await roomInstance .request({ method: "PUT", url: "challenge/", data: {...data }, }) .then((res) => res.data.data) .catch((err) => { throw err; }); }; export const deleteParcours = async (data) => { return await roomInstance .request({ method: "DELETE", url: "parcours/", data: {...data} }) .then((res) => res.data.data) .catch((err) => { throw err; }); }; export const getCorrectionInfo = async (data) => { return await roomInstance .request({ method: "GET", url: "correct/", params: {...data} }) .then((res) => res.data.data) .catch((err) => { throw err; }); }; export const toggleRoomLock = async (data) => { return await roomInstance .request({ method: "POST", url: "lock/", data: {...data} }) .then((res) => res.data.data) .catch((err) => { throw err; }); }; export const togglePublicResult = async (data) => { return await roomInstance .request({ method: "POST", url: "public/", data: {...data} }) .then((res) => res.data.data) .catch((err) => { throw err; }); }; export const changeRoomName = async (data) => { return await roomInstance .request({ method: "POST", url: "change_name/", data: {...data} }) .then((res) => res.data.data) .catch((err) => { throw err; }); };