diff --git a/src/schema.ts b/src/schema.ts index e96cad3..190be16 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -354,6 +354,14 @@ async function resolveLandingNetworkStory(focusKind: LandingNetworkKind, itemLim LIMIT 1 RETURN 1 ) > 0 + FILTER LENGTH( + FOR hub IN nodes + FILTER hub.node_type == 'logistics' OR hub.node_type == null + FILTER hub.product_uuid == null + FILTER hub.latitude != null AND hub.longitude != null + LIMIT 1 + RETURN 1 + ) > 0 SORT RAND() LIMIT 1 RETURN supplier @@ -384,7 +392,10 @@ async function resolveLandingNetworkStory(focusKind: LandingNetworkKind, itemLim LIMIT @limit RETURN MERGE(hub, {distance_km: dist}) `, { lat: focus.latitude, lon: focus.longitude, limit }) - const hubs = await hubsCursor.all() + const hubs = await hubsCursor.all() as ArangoDoc[] + if (offers.length === 0 || hubs.length === 0) { + throw new Error('No complete supplier story with offers and nearby hubs is available') + } return { focus: mapLandingNetworkPoint(focus, 'SUPPLIER'), offers: offers.map(mapLandingNetworkOffer), @@ -434,12 +445,17 @@ async function resolveLandingNetworkStory(focusKind: LandingNetworkKind, itemLim `, { lat: focus.latitude, lon: focus.longitude, offer_limit: limit * 4 }) const offers = await offersCursor.all() as ArangoDoc[] const visibleOffers = offers.slice(0, limit) + const products = landingProductsFromOffers(visibleOffers, limit) + const suppliers = landingSuppliersFromOffers(visibleOffers, limit) + if (visibleOffers.length === 0 || products.length === 0 || suppliers.length === 0) { + throw new Error('No complete hub story with nearby products and suppliers is available') + } return { focus: mapLandingNetworkPoint(focus, 'HUB'), offers: visibleOffers.map(mapLandingNetworkOffer), hubs: [], - products: landingProductsFromOffers(visibleOffers, limit), - suppliers: landingSuppliersFromOffers(visibleOffers, limit), + products, + suppliers, } }