question.api.ts 769 Bytes
Newer Older
Jiwon Yoon's avatar
Jiwon Yoon committed
1
import axios from "axios";
Jiwon Yoon's avatar
Jiwon Yoon committed
2
import { BasicQuestionType } from "../types";
Jiwon Yoon's avatar
Jiwon Yoon committed
3
4
import baseUrl from "./baseUrl";

Jiwon Yoon's avatar
Jiwon Yoon committed
5
6
7
8
9
10
11
12
13
14
15
export const createQuestion = async (surveyId: string) => {
  const { data } = await axios.post(
    `${baseUrl}/surveys/${surveyId}/questions`,
    {
      type: "essay",
      title: "",
      isRequired: false,
      comment: "",
      content: { choices: [] },
    }
  );
Jiwon Yoon's avatar
Jiwon Yoon committed
16
17
18
19
  return data;
};

export const updateQuestion = async (question: BasicQuestionType) => {
Jiwon Yoon's avatar
Jiwon Yoon committed
20
21
22
23
  const { data } = await axios.put(
    `${baseUrl}/questions/update/${question._id}`,
    question
  );
Jiwon Yoon's avatar
Jiwon Yoon committed
24
25
26
  return data;
};

27
28
29
30
export const deleteQuestion = async (questionId: string) => {
  const { data } = await axios.delete(
    `${baseUrl}/questions/delete/${questionId}`
  );
Jiwon Yoon's avatar
Jiwon Yoon committed
31
32
  return data;
};