ANTON KADACH

Generation

fix invalid codeWed, 18 Jan 2023

const getParcelPickups = (parcels) => { return Promise.all( parcels.map((parcel) => { const [warehouse] = cacheContainer.warehousesByMerchantId.get(Number(parcel.merchantId)) || []; const pickupRegion = cacheContainer.pickupRegionsByGeoId.get(warehouse.geoId); return getPickupFromParcel({ warehouse, pickupRegion }); })) }; const getPickupFromParcel = async ({ warehouse, pickupRegion }) => { const isSelfDelivery = await selfDeliveryService.merchantHasSelfDelivery(warehouse.merchantId); const zeroMileTerminalGeoId = getZeroMileTerminalGeoId(pickupRegion); const zeroMile = zeroMileTerminalGeoId ? { terminalGeoId: zeroMileTerminalGeoId, carrierCode: getZeromileCarrierCode(pickupRegion, zeroMileTerminalGeoId) } : null; } const terminalGeoId = zeroMile ? zeroMile.terminalGeoId : warehouse.geoId; return { warehouse: warehouse.toTimeCalculatorFormat(), carrierCode: getCarrierCodeForPickup({ isSelfDelivery, zeroMile }), terminalGeo: terminalGeoId, withSortingCenter: Boolean(pickupRegion?.hasSortingCenter) }; const getCarrierCodeForPickup = ({ isSelfDelivery, zeroMile }) => { if (isSelfDelivery) { return config.selfDeliveryService.carrierCode; } if (zeroMile) { return zeroMile.carrierCode; } return null; }; const getZeromileCarrierCode = (pickupRegion, zeroMileTerminalGeoId) => { if (zeroMileTerminalGeoId) return pickupRegion.zeromileCarrierCode; return null; }; const getZeroMileTerminalGeoId = (pickupRegion) => { if (!pickupRegion) return null; if (isMoscow(pickupRegion)) return moscowId; if (isMoscowRegion(pickupRegion)) return moscowRegionId; return null; };

### Examples #### Prettier

Questions about programming?Chat with your personal AI assistant