This commit is contained in:
+1
-1
Submodule graphql-contracts updated: e96e5afd01...1af133dd20
+32
-1
@@ -99,6 +99,11 @@ export const typeDefs = `#graphql
|
|||||||
name: String
|
name: String
|
||||||
imageUrl: String
|
imageUrl: String
|
||||||
offersCount: Int
|
offersCount: Int
|
||||||
|
averagePrice: Float
|
||||||
|
priceVariationPercent: Float
|
||||||
|
priceSeries: [Float!]!
|
||||||
|
currency: String
|
||||||
|
unit: String
|
||||||
}
|
}
|
||||||
|
|
||||||
type Supplier {
|
type Supplier {
|
||||||
@@ -255,6 +260,11 @@ function productView(doc: ArangoDoc, catalog: Map<string, ProductCatalogItem>) {
|
|||||||
name: product?.name ?? doc.product_name ?? doc.name ?? null,
|
name: product?.name ?? doc.product_name ?? doc.name ?? null,
|
||||||
imageUrl: product?.imageUrl ?? null,
|
imageUrl: product?.imageUrl ?? null,
|
||||||
offersCount: doc.offers_count ?? doc.offersCount ?? null,
|
offersCount: doc.offers_count ?? doc.offersCount ?? null,
|
||||||
|
averagePrice: doc.average_price ?? null,
|
||||||
|
priceVariationPercent: doc.price_variation_percent ?? null,
|
||||||
|
priceSeries: doc.price_series ?? [],
|
||||||
|
currency: doc.currency ?? null,
|
||||||
|
unit: doc.unit ?? null,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1368,9 +1378,30 @@ export const resolvers = {
|
|||||||
${bounds.filter}
|
${bounds.filter}
|
||||||
COLLECT product_uuid = node.product_uuid INTO offers
|
COLLECT product_uuid = node.product_uuid INTO offers
|
||||||
LET first_offer = FIRST(offers).node
|
LET first_offer = FIRST(offers).node
|
||||||
|
LET price_series = (
|
||||||
|
FOR offer_row IN offers
|
||||||
|
LET price = TO_NUMBER(offer_row.node.price_per_unit)
|
||||||
|
FILTER price > 0
|
||||||
|
SORT price ASC
|
||||||
|
RETURN price
|
||||||
|
)
|
||||||
|
LET average_price = LENGTH(price_series) > 0 ? AVERAGE(price_series) : null
|
||||||
|
LET price_variation_percent = average_price > 0
|
||||||
|
? ((LAST(price_series) - FIRST(price_series)) / 2 / average_price) * 100
|
||||||
|
: 0
|
||||||
SORT first_offer.product_name ASC
|
SORT first_offer.product_name ASC
|
||||||
LIMIT @offset, @limit
|
LIMIT @offset, @limit
|
||||||
RETURN { uuid: product_uuid, product_uuid, product_name: first_offer.product_name, offers_count: LENGTH(offers) }
|
RETURN {
|
||||||
|
uuid: product_uuid,
|
||||||
|
product_uuid,
|
||||||
|
product_name: first_offer.product_name,
|
||||||
|
offers_count: LENGTH(offers),
|
||||||
|
average_price,
|
||||||
|
price_variation_percent,
|
||||||
|
price_series,
|
||||||
|
currency: first_offer.currency,
|
||||||
|
unit: first_offer.unit
|
||||||
|
}
|
||||||
`, { offset: args.offset ?? 0, limit: args.limit ?? 50, ...bounds.vars })
|
`, { offset: args.offset ?? 0, limit: args.limit ?? 50, ...bounds.vars })
|
||||||
const products = await cursor.all()
|
const products = await cursor.all()
|
||||||
return products.map((product: ArangoDoc) => productView(product, productCatalog))
|
return products.map((product: ArangoDoc) => productView(product, productCatalog))
|
||||||
|
|||||||
Reference in New Issue
Block a user