Code review feedback

This commit is contained in:
Greg 2021-07-06 11:19:09 -06:00
parent 5c5f97cce1
commit 88c62ae708
1 changed files with 8 additions and 4 deletions

View File

@ -24,11 +24,15 @@ const updateReadyPageStatus = async ( status ) => {
// The page will be in a draft state, so we need to filter on that status
statusFilter = 'draft';
}
const getPostsResponse = await client.get(`${wpPagesEndpoint}?search=ready&status=${statusFilter}`);
const pageId = getPostsResponse.data[0].id;
// Update the page to the new status
await client.post(`${wpPagesEndpoint}/${pageId}`, { 'status': status });
const getPostsResponse = await client.get(`${wpPagesEndpoint}?search=ready&status=${statusFilter}`);
if ( getPostsResponse.data && getPostsResponse.data.length > 0) {
const pageId = getPostsResponse.data[0].id;
// Update the page to the new status
await client.post(`${wpPagesEndpoint}/${pageId}`, { 'status': status });
} else {
throw new Error('Ready page not found.');
}
}
module.exports = updateReadyPageStatus;