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

Refactor getStoreChannels function #1187

Closed
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
24 changes: 11 additions & 13 deletions lib/theme-api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,22 +208,20 @@ async function getChannelActiveTheme({ accessToken, apiHost, storeHash, channelI
*/
async function getStoreChannels({ accessToken, apiHost, storeHash }) {
try {
const sitesResponse = await networkUtils.sendApiRequest({
url: `${apiHost}/stores/${storeHash}/v3/sites`,
accessToken,
});
const channelsResponse = await networkUtils.sendApiRequest({
url: `${apiHost}/stores/${storeHash}/v3/channels`,
accessToken,
});

const storefrontChannels = channelsResponse.data.data.filter(
(channel) => channel.type === 'storefront',
);
const [sitesResponse, channelsResponse] = await Promise.all([
networkUtils.sendApiRequest({
url: `${apiHost}/stores/${storeHash}/v3/sites`,
accessToken,
}),
networkUtils.sendApiRequest({
url: `${apiHost}/stores/${storeHash}/v3/channels?type:in=storefront`,
accessToken,
}),
]);

return sitesResponse.data.data.filter(
(site) =>
storefrontChannels.filter((channel) => channel.id === site.channel_id).length > 0,
channelsResponse.data.data.filter((channel) => channel.id === site.channel_id).length > 0,
);
} catch (err) {
throw new Error(`Could not fetch a list of the store channels: ${err.message}`);
Expand Down
Loading