requests for auth/register

This commit is contained in:
Tatiana Nikolaeva 2025-05-10 15:56:50 +05:00
parent 9a3f05ef60
commit bc293f6370
9 changed files with 348 additions and 63 deletions

View file

@ -0,0 +1,29 @@
import {BASE_URL, createRequestConfig, handleResponse} from "./BaseApi.ts";
export interface INewQuestion{
title: string;
questionType: string;
answerVariants: string[];
}
//
// export interface IErrorQuestionResponse {
//
// }
export const addNewQuestion = async (surveyId: number, question: INewQuestion) => {
const token = localStorage.getItem("token");
if (!token) {
throw new Error("Токен отсутствует");
}
try{
const response = await fetch(`${BASE_URL}/surveys/${surveyId}/questions`, {
...createRequestConfig('POST'),
body: JSON.stringify(question),
})
return await handleResponse(response)
} catch (error){
throw new Error(`Error when adding a new question: ${error}`);
}
}