Posting an answer to the REST API

We are going to change the implementation for posting an answer to use the access token and our generic http function. Let's revise the implementation of the postAnswer function to the following:

export const postAnswer = async (
answer: PostAnswerData,
): Promise<AnswerData | undefined> => {
const accessToken = await getAccessToken();
try {
const result = await http<PostAnswerData, AnswerData>({
path: '/questions/answer',
method: 'post',
body: answer,
accessToken,
});
if (result.ok) {
return result.parsedBody;
} else {
return undefined;
}
} catch (ex) {
console.error(ex);
return undefined;
}
};

This follows the same pattern as the postQuestion function, getting the access token from Auth0 and making the HTTP POST request with the JWT using the http function. 

That completes the changes needed for posting an answer.

We can now remove the questions array mock data from QuestionsData.ts as this is no longer used. The wait function can also be removed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.173.32