Generateurv2/frontend/requests/requests.room.js

254 lines
5.2 KiB
JavaScript
Raw Normal View History

2022-05-18 10:15:54 +02:00
import { roomInstance } from "../apis/roomInstance.intance.js";
2022-06-11 23:39:03 +02:00
import { isBrowser } from "../utils/utils.js";
2022-05-18 10:15:54 +02:00
export const createRoom = async (data) => {
return await roomInstance
.request({
method: "POST",
url: "room/",
2022-06-11 23:39:03 +02:00
data: { ...data },
headers: {
Authorization:
isBrowser ?
localStorage.getItem("token") !== null
? `Token ${localStorage.getItem("token")}`
: null: null
},
2022-05-18 10:15:54 +02:00
})
.then((res) => res.data.data);
};
2022-06-24 13:42:16 +02:00
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);
};
2022-05-18 10:15:54 +02:00
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;
});;
};
2022-06-24 13:42:16 +02:00
export const checkRoom = async (code, clientId) => {
2022-05-18 10:15:54 +02:00
return await roomInstance
.request({
method: "GET",
url: "room/" + code,
2022-06-24 13:42:16 +02:00
params: {clientId}
2022-05-18 10:15:54 +02:00
})
.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;
});
};
2022-06-24 13:42:16 +02:00
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;
});
};
2022-05-18 10:15:54 +02:00
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;
});
};
2022-06-24 13:42:16 +02:00
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;
});
};
2022-05-18 10:15:54 +02:00