Skip to content

Commit

Permalink
feat: フォームの回答可能期間を指定できるように
Browse files Browse the repository at this point in the history
  • Loading branch information
rito528 committed Feb 9, 2024
1 parent 2e3ca87 commit 787533e
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/features/form/api/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ export const createForm = async (
formTitle: string,
formDescription: string,
questions: Questions[],
responsePeriod: {
startAt: string,
endAt: string
}
responsePeriod: { startAt: string; endAt: string; } | undefined
) => {
const titleAndDescription = JSON.stringify({
title: formTitle,
Expand All @@ -132,7 +129,7 @@ export const createForm = async (
return response.json()
})
.then((jsonResponse) => jsonResponse.id)
.then(async (createdFormId) => {
.then(async (createdFormId: number) => {
const body = JSON.stringify({
form_id: createdFormId,
questions: questions.map((question) => {
Expand All @@ -146,17 +143,33 @@ export const createForm = async (
})
})

questions.forEach((question) => question.choices.forEach((choice) => choice))
console.log(body)

return await fetch(`${apiServerUrl}/forms/questions`, {
const responseAndCreatedFormId: [Response, number] = [await fetch(`${apiServerUrl}/forms/questions`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body,
cache: 'no-cache',
}), createdFormId];

return responseAndCreatedFormId;
}).then(async ([response, createdFormId]) => {
if (!response.ok) {
// TODO: 異常系処理を書く
}

if (responsePeriod == undefined) {
// TODO: 回答可能期間を指定しなかったときの処理を書く
}

return await fetch(`${apiServerUrl}/forms/${createdFormId}?start_at=${encodeURIComponent(`${responsePeriod?.startAt}:00+09:00`)}&end_at=${encodeURIComponent(`${responsePeriod?.endAt}:00+09:00`)}`, {
method: 'PATCH',
headers: {
Accept: 'application/json',
Authorization: `Bearer ${token}`,
},
cache: 'no-cache',
})
})

Expand Down

0 comments on commit 787533e

Please sign in to comment.