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}`); } }