saleor-apps-redis_apl/apps/invoices/src/modules/app-configuration/fallback-app-config.ts

30 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-02-07 19:25:36 +00:00
import { AppConfig } from "./app-config";
import { AppConfigContainer } from "./app-config-container";
import { ChannelFragment, ShopInfoFragment } from "../../../generated/graphql";
/**
* TODO Test
*/
export const FallbackAppConfig = {
createFallbackConfigFromExistingShopAndChannels(
channels: ChannelFragment[],
shopAddress: ShopInfoFragment | null
) {
return (channels ?? []).reduce<AppConfig>(
(state, channel) => {
return AppConfigContainer.setChannelAddress(state)(channel.slug)({
city: shopAddress?.companyAddress?.city ?? "",
cityArea: shopAddress?.companyAddress?.cityArea ?? "",
companyName: shopAddress?.companyAddress?.companyName ?? "",
country: shopAddress?.companyAddress?.country.country ?? "",
countryArea: shopAddress?.companyAddress?.countryArea ?? "",
postalCode: shopAddress?.companyAddress?.postalCode ?? "",
streetAddress1: shopAddress?.companyAddress?.streetAddress1 ?? "",
streetAddress2: shopAddress?.companyAddress?.streetAddress2 ?? "",
});
},
{ shopConfigPerChannel: {} }
);
},
};