Files
web2.0-frontend/src/models/SignupForm.ts
T
2019-03-13 15:53:46 +02:00

64 lines
1.3 KiB
TypeScript

import axios from "axios";
import { getAuthHeader } from "../auth";
import * as qs from "query-string";
const url = `${process.env.API_URL}/signupForm/`;
export interface SignupForm {
id: number;
title: string;
start_time: string;
end_time: string;
questions: any[];
visible: boolean;
}
export async function getForms(): Promise<SignupForm[]> {
try {
const resp = await axios.get(url);
const results = resp.data["results"];
return results;
} catch (err) {
console.error(err);
throw err;
}
}
export async function getForm(id: number): Promise<SignupForm> {
try {
const resp = await axios.get(`${url}${id}/`);
return resp.data;
} catch (err) {
console.error(err);
throw err;
}
}
export async function createForm(data): Promise<SignupForm> {
try {
const resp = await axios.post(url, data, {
headers: {
"Authorization": getAuthHeader(),
},
});
return resp.data;
} catch (err) {
console.error(err);
throw err;
}
}
export async function updateForm(data): Promise<SignupForm> {
try {
const putUrl = `${url}${data.id}/`;
const resp = await axios.put(putUrl, data, {
headers: {
"Authorization": getAuthHeader(),
},
});
return resp.data;
} catch (err) {
console.error(err);
throw err;
}
}