survey.api.ts 1.47 KB
Newer Older
Jiwon Yoon's avatar
Jiwon Yoon committed
1
2
3
4
import axios from "axios";
import { SurveyType } from "../types";
import baseUrl from "./baseUrl";

Jiwon Yoon's avatar
Jiwon Yoon committed
5
6
7
8
9
10
export const createSurvey = async (survey: SurveyType) => {
  const { data } = await axios.post(`${baseUrl}/surveys/create`, survey);
  return data;
};

export const getSurvey = async (surveyId: string) => {
jang dong hyeok's avatar
jang dong hyeok committed
11
  const { data } = await axios.get(`${baseUrl}/surveys/${surveyId}/edit`);
Jiwon Yoon's avatar
Jiwon Yoon committed
12
13
  return data;
};
14

Lee SeoYeon's avatar
Lee SeoYeon committed
15
16
17
18
19
20
21
22
23
24
25
26
27
export const surveycreate = async (surveyId: string) => {
  const { data } = await axios.get(`${baseUrl}/surveys/${surveyId}/create`);
  return data;
};

export const surveyscreate = async (survey: SurveyType) => {
  const { data } = await axios.put(
    `${baseUrl}/surveys/${survey._id}/create`,
    survey
  );
  return data;
};

28
export const ansSurvey = async (surveyId: string) => {
29
  const { data } = await axios.get(`${baseUrl}/surveys/${surveyId}`);
Jiwon Yoon's avatar
Jiwon Yoon committed
30
31
  return data;
};
32

33
34
35
36
export const getSurveys = async () => {
  const { data } = await axios.get(`${baseUrl}/surveys/`);
  return data;
};
Jiwon Yoon's avatar
Jiwon Yoon committed
37
38
39

export const editSurvey = async (survey: SurveyType) => {
  const { data } = await axios.put(
jang dong hyeok's avatar
jang dong hyeok committed
40
    `${baseUrl}/surveys/${survey._id}/edit`,
Jiwon Yoon's avatar
Jiwon Yoon committed
41
42
43
44
    survey
  );
  return data;
};
jang dong hyeok's avatar
.    
jang dong hyeok committed
45
46
47
export const resultSurvey = async (survey: SurveyType) => {
  const { data } = await axios.put(
    `${baseUrl}/surveys/${survey._id}/result`,
Jiwon Yoon's avatar
Jiwon Yoon committed
48
49
50
51
    survey
  );
  return data;
};
52
53

export const deleteSurvey = async (surveyId: string) => {
jang dong hyeok's avatar
jang dong hyeok committed
54
  const { data } = await axios.delete(`${baseUrl}/surveys/${surveyId}/delete`);
55
56
  return data;
};