| 123456789101112131415161718192021222324252627282930 |
- import apiEndpoints from '../apiEndpoints';
- import { QuestionData } from '../../utils/interface/questionInterface';
-
- interface QuestionResponse {
- message: string;
- question: { [key: string]: string };
- }
-
- export const postQuestion = async (
- questionData: QuestionData
- ): Promise<QuestionResponse> => {
- const response = await fetch(
- `http://localhost:3000${apiEndpoints.question}`,
- {
- method: 'POST',
- body: JSON.stringify(questionData),
- headers: {
- 'Content-Type': 'application/json',
- },
- }
- );
-
- const data: QuestionResponse = await response.json();
-
- if (!response.ok) {
- throw new Error(data.message || 'Something went wrong!');
- }
-
- return data;
- };
|