Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

回答の取得に失敗する不具合の修正 #301

Merged
merged 3 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading