47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import axiosInstance from "./_axiosInstance";
|
|
import { AuthLoginResponse, CategoryResponse, Pagination, QuestionResponse, UserResponse } from "./types";
|
|
|
|
export const get_questions = async (page: number, test_id?: number, category_id?: number) => {
|
|
const response = await axiosInstance.get<Pagination<QuestionResponse>>("/api/questions/", {
|
|
params: {
|
|
page,
|
|
test_id,
|
|
category_id
|
|
}
|
|
})
|
|
|
|
return response.data;
|
|
}
|
|
|
|
export const get_question = async (id: number) => {
|
|
const response = await axiosInstance.get<{
|
|
data: QuestionResponse
|
|
}>(`/api/questions/${id}`);
|
|
|
|
return response.data;
|
|
}
|
|
|
|
export const get_current_user = async () => {
|
|
const response = await axiosInstance.get<{
|
|
user: UserResponse
|
|
}>("/api/auth/me/");
|
|
|
|
return response.data;
|
|
}
|
|
|
|
export const get_categories = async () => {
|
|
const response = await axiosInstance.get<{
|
|
data: CategoryResponse[]
|
|
}>("/api/categories/");
|
|
|
|
return response.data;
|
|
}
|
|
|
|
export const post_login = async (email: string, password: string) => {
|
|
const response = await axiosInstance.post<AuthLoginResponse>("/api/auth/login/", {
|
|
email,
|
|
password
|
|
});
|
|
|
|
return response.data;
|
|
} |