134 lines
2.6 KiB
JavaScript
134 lines
2.6 KiB
JavaScript
import { exoInstance } from "../apis/exoInstance.instance.js";
|
|
import { csvExtParse } from "../utils/utils.js";
|
|
|
|
|
|
export const getExos = async (code='all') => {
|
|
|
|
return await exoInstance.request({
|
|
method: "GET",
|
|
url: "exercices/",
|
|
params: { code: code},
|
|
}).then(res=>res.data.data)
|
|
};
|
|
|
|
export const createExo = async (data) => {
|
|
return await exoInstance.request({
|
|
url: `exercices/`,
|
|
data: data,
|
|
method: "POST",
|
|
})
|
|
.then((res) => {
|
|
return res.data
|
|
})
|
|
.catch((err) => {
|
|
throw err
|
|
});
|
|
//return response.data.data;
|
|
};
|
|
|
|
export const delExo = async (id_code) => {
|
|
|
|
return await exoInstance.request({
|
|
url: `exercices/`,
|
|
data: { 'id_code': id_code},
|
|
method: "DELETE",
|
|
})
|
|
.then((res) => res.data)
|
|
.catch((err) => {throw err});
|
|
}
|
|
|
|
export const editExo = async (data) => {
|
|
|
|
return await exoInstance.request({
|
|
url: `exercices/`,
|
|
data: data,
|
|
method: "PUT",
|
|
})
|
|
.then((res) => res.data)
|
|
.catch((err) => {
|
|
throw err
|
|
});
|
|
}
|
|
|
|
|
|
export const getTags = async () => {
|
|
const response = await exoInstance.request({
|
|
method: "GET",
|
|
url: "/tags/",
|
|
});
|
|
return await exoInstance.request({
|
|
method: "GET",
|
|
url: "/tags/",
|
|
}).then(res=>res.data.data);
|
|
}
|
|
|
|
export const setTags = async (data) => {
|
|
return await exoInstance.request({
|
|
method: 'POST',
|
|
url: '/tags/',
|
|
data: {...data}
|
|
})
|
|
}
|
|
|
|
export const delTag = async (data) => {
|
|
return await exoInstance.request({
|
|
method: 'DELETE',
|
|
url: '/tags/',
|
|
data: {...data}
|
|
}).then(res=>res.data.data)
|
|
}
|
|
|
|
|
|
export const editorOut = async (data) => {
|
|
return await exoInstance
|
|
.request({
|
|
method: "post",
|
|
url: "editor/",
|
|
data: { code: data },
|
|
})
|
|
.then((res) => res.data);
|
|
};
|
|
|
|
|
|
|
|
|
|
export const csvGen = async (code, name) => {
|
|
return await exoInstance
|
|
.request({
|
|
method: "get",
|
|
url: `csv/${code}`,
|
|
})
|
|
.then((res) => {
|
|
let blob = new Blob([res.data], {
|
|
type: "text/csv",
|
|
});
|
|
const downloadUrl = window.URL.createObjectURL(blob);
|
|
const link = document.createElement("a");
|
|
link.href = downloadUrl;
|
|
link.setAttribute("download", csvExtParse(name));
|
|
document.body.appendChild(link);
|
|
link.click();
|
|
link.remove();
|
|
});
|
|
};
|
|
|
|
export const pdfGen = async (data) => {
|
|
return await exoInstance
|
|
.request({
|
|
method: "post",
|
|
url: `pdf/`,
|
|
data: {...data}
|
|
})
|
|
}
|
|
|
|
export const getModelFile = async (code) => {
|
|
return await exoInstance
|
|
.request({
|
|
method: "get",
|
|
url: `model/`,
|
|
params:{code: code}
|
|
})
|
|
}
|
|
|
|
|