Skip to content

Commit

Permalink
Merge pull request #301 from GiganticMinecraft/fix/answer
Browse files Browse the repository at this point in the history
回答の取得に失敗する不具合の修正
  • Loading branch information
rito528 authored Feb 1, 2024
2 parents 8be8eae + 9ce7efa commit 1d96c8d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"lint:fix": "next lint --fix",
"fmt": "prettier --check --log-level=warn './**/*.{ts,tsx,css}'",
"fmt:fix": "prettier --write --log-level=warn './**/*.{ts,tsx,css}'",
"postinstall": "typesync || :"
"postinstall": "typesync || :",
"pretty": "yarn lint:fix && yarn fmt:fix"
},
"dependencies": {
"@azure/msal-browser": "^3.2.0",
Expand Down
33 changes: 17 additions & 16 deletions src/features/form/api/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
} from '../types/formSchema';
import type { BatchAnswer, Form, FormQuestion } from '../types/formSchema';

const apiServerUrl = 'http://localhost:9000';

export const getForms = async (token: string) => {
const response = await fetch('http://localhost:9000/forms', {
const response = await fetch(`${apiServerUrl}/forms`, {
method: 'GET',
headers: {
Accept: 'application/json',
Expand All @@ -22,7 +24,7 @@ export const getForms = async (token: string) => {
};

export const getForm = async (formId: number, token: string): Promise<Form> => {
const response = await fetch(`http://localhost:9000/forms/${formId}`, {
const response = await fetch(`${apiServerUrl}/forms/${formId}`, {
method: 'GET',
headers: {
Accept: 'application/json',
Expand All @@ -38,17 +40,14 @@ export const getFormQuestions = async (
formId: number,
token: string
): Promise<FormQuestion[]> => {
const response = await fetch(
`http://localhost:9000/forms/${formId}/questions`,
{
method: 'GET',
headers: {
Accept: 'application/json',
Authorization: `Bearer ${token}`,
},
cache: 'no-cache',
}
);
const response = await fetch(`${apiServerUrl}/forms/${formId}/questions`, {
method: 'GET',
headers: {
Accept: 'application/json',
Authorization: `Bearer ${token}`,
},
cache: 'no-cache',
});

return questionsSchema.parse(await response.json());
};
Expand All @@ -63,7 +62,7 @@ export const postAnswers = async (
answers,
});

const response = await fetch(`http://localhost:9000/forms/answers`, {
const response = await fetch(`${apiServerUrl}/forms/answers`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -77,12 +76,14 @@ export const postAnswers = async (
};

export const getAllAnswers = async (token: string): Promise<BatchAnswer[]> => {
return await fetch(`http://localhost:9000/forms/answers`, {
const response = await fetch(`${apiServerUrl}/forms/answers`, {
method: 'GET',
headers: {
Accept: 'application/json',
Authorization: `Bearer ${token}`,
},
cache: 'no-cache',
}).then(async (response) => batchAnswersSchema.parse(await response.json()));
});

return batchAnswersSchema.parse(await response.json());
};
2 changes: 1 addition & 1 deletion src/features/form/types/formSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export const answerSchema = z.object({
export const batchAnswerSchema = z.object({
uuid: z.string(),
timestamp: z.string().datetime(),
title: z.string(),
form_id: z.number(),
title: z.string(),
answers: z.array(answerSchema),
});

Expand Down

0 comments on commit 1d96c8d

Please sign in to comment.