survey.api.ts 1.78 KB
Newer Older
Yoon, Daeki's avatar
Yoon, Daeki committed
1
import axios from "./axios.config";
Yoon, Daeki's avatar
Yoon, Daeki committed
2
import { CreateQuestionData, IQuestionData, ISurvey } from "../types";
Jiwon Yoon's avatar
Jiwon Yoon committed
3
4
import baseUrl from "./baseUrl";

Yoon, Daeki's avatar
Yoon, Daeki committed
5
6
7
8
9
10
11
12
13
14
15
export const addQuestion = async (
  surveyId: string,
  question: IQuestionData
) => {
  const { data } = await axios.post(
    `${baseUrl}/surveys/${surveyId}/questions`,
    question
  );
  return data;
};

Yoon, Daeki's avatar
Yoon, Daeki committed
16
export const createSurvey = async (survey: ISurvey) => {
Yoon, Daeki's avatar
Yoon, Daeki committed
17
  const { data } = await axios.post(`${baseUrl}/surveys`, survey);
Jiwon Yoon's avatar
Jiwon Yoon committed
18
19
20
  return data;
};

Yoon, Daeki's avatar
Yoon, Daeki committed
21
22
23
24
25
26
27
28
29
30
31
32
export const deleteQuestion = async (surveyId: string, questionId: string) => {
  const { data } = await axios.delete(
    `${baseUrl}/surveys/${surveyId}/questions/${questionId}`
  );
  return data;
};

export const deleteSurvey = async (surveyId: string) => {
  const { data } = await axios.delete(`${baseUrl}/surveys/${surveyId}`);
  return data;
};

Jiwon Yoon's avatar
Jiwon Yoon committed
33
export const getSurvey = async (surveyId: string) => {
jang dong hyeok's avatar
jang dong hyeok committed
34
  const { data } = await axios.get(`${baseUrl}/surveys/${surveyId}/edit`);
Jiwon Yoon's avatar
Jiwon Yoon committed
35
36
  return data;
};
37

Yoon, Daeki's avatar
Yoon, Daeki committed
38
export const getSurveyById = async (surveyId: string) => {
39
  const { data } = await axios.get(`${baseUrl}/surveys/${surveyId}`);
Jiwon Yoon's avatar
Jiwon Yoon committed
40
41
  return data;
};
42

43
44
45
46
export const getSurveys = async () => {
  const { data } = await axios.get(`${baseUrl}/surveys/`);
  return data;
};
Jiwon Yoon's avatar
Jiwon Yoon committed
47

Yoon, Daeki's avatar
Yoon, Daeki committed
48
export const resultSurvey = async (survey: ISurvey) => {
jang dong hyeok's avatar
.    
jang dong hyeok committed
49
50
  const { data } = await axios.put(
    `${baseUrl}/surveys/${survey._id}/result`,
Jiwon Yoon's avatar
Jiwon Yoon committed
51
52
53
54
    survey
  );
  return data;
};
55

Yoon, Daeki's avatar
Yoon, Daeki committed
56
57
58
59
60
61
62
63
64
65
66
67
68
export const updateQuestion = async (
  surveyId: string,
  question: CreateQuestionData
) => {
  const { data } = await axios.put(
    `${baseUrl}/surveys/${surveyId}/questions/${question._id}`,
    question
  );
  return data;
};

export const updateSurvey = async (survey: ISurvey) => {
  const { data } = await axios.put(`${baseUrl}/surveys/${survey._id}`, survey);
69
70
  return data;
};