Skip to content

Commit

Permalink
feat: フォーム作成時に質問も同時に追加されるように
Browse files Browse the repository at this point in the history
  • Loading branch information
rito528 committed May 1, 2024
1 parent 2dc1864 commit a77b165
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ const QuestionComponent = ({
control={
<Checkbox {...register(`questions.${questionId}.is_required`)} />
}
required
/>
<Button
variant="outlined"
Expand Down
26 changes: 25 additions & 1 deletion src/app/api/form/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,31 @@ export async function POST(req: NextRequest) {
}
);

return NextResponse.json({}, { status: patchFormResponse.status });
if (!patchFormResponse.ok) {
return NextResponse.json({}, { status: patchFormResponse.status });
}

const addQuestionsResponse = await fetch(
`${req.nextUrl.origin}/api/questions`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
form_id: parsedCreateFormResponse.data.id,
questions: form.questions.map((question) => {
return {
...question,
choices: question.choices.map((choice) => choice.choice),
};
}),
}),
cache: 'no-cache',
}
);

return NextResponse.json({}, { status: addQuestionsResponse.status });
}

export async function PATCH(req: NextRequest) {
Expand Down

0 comments on commit a77b165

Please sign in to comment.