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

Yoon, Daeki's avatar
Yoon, Daeki committed
5
export const createSurvey = async (survey: ISurvey) => {
Yoon, Daeki's avatar
Yoon, Daeki committed
6
  const { data } = await axios.post(`${baseUrl}/surveys`, survey);
Jiwon Yoon's avatar
Jiwon Yoon committed
7
8
9
10
  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

Yoon, Daeki's avatar
Yoon, Daeki committed
15
export const getSurveyById = async (surveyId: string) => {
16
  const { data } = await axios.get(`${baseUrl}/surveys/${surveyId}`);
Jiwon Yoon's avatar
Jiwon Yoon committed
17
18
  return data;
};
19

20
21
22
23
export const getSurveys = async () => {
  const { data } = await axios.get(`${baseUrl}/surveys/`);
  return data;
};
Jiwon Yoon's avatar
Jiwon Yoon committed
24

Yoon, Daeki's avatar
Yoon, Daeki committed
25
26
export const updateSurvey = async (survey: ISurvey) => {
  const { data } = await axios.put(`${baseUrl}/surveys/${survey._id}`, survey);
Jiwon Yoon's avatar
Jiwon Yoon committed
27
28
  return data;
};
Yoon, Daeki's avatar
Yoon, Daeki committed
29
30

export const resultSurvey = async (survey: ISurvey) => {
jang dong hyeok's avatar
.    
jang dong hyeok committed
31
32
  const { data } = await axios.put(
    `${baseUrl}/surveys/${survey._id}/result`,
Jiwon Yoon's avatar
Jiwon Yoon committed
33
34
35
36
    survey
  );
  return data;
};
37
38

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