Add product price summaries
Build and deploy Docker image / build (push) Successful in 1m17s

This commit is contained in:
Ruslan Bakiev
2026-08-24 14:20:22 +07:00
parent a7bb8a9444
commit 3398f82119
2 changed files with 33 additions and 2 deletions
+32 -1
View File
@@ -99,6 +99,11 @@ export const typeDefs = `#graphql
name: String
imageUrl: String
offersCount: Int
averagePrice: Float
priceVariationPercent: Float
priceSeries: [Float!]!
currency: String
unit: String
}
type Supplier {
@@ -255,6 +260,11 @@ function productView(doc: ArangoDoc, catalog: Map<string, ProductCatalogItem>) {
name: product?.name ?? doc.product_name ?? doc.name ?? null,
imageUrl: product?.imageUrl ?? 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}
COLLECT product_uuid = node.product_uuid INTO offers
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
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 })
const products = await cursor.all()
return products.map((product: ArangoDoc) => productView(product, productCatalog))