requests for auth/register
This commit is contained in:
parent
9a3f05ef60
commit
bc293f6370
9 changed files with 348 additions and 63 deletions
29
SurveyFrontend/src/api/QuestionApi.ts
Normal file
29
SurveyFrontend/src/api/QuestionApi.ts
Normal 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}`);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue