Add offers_count field to ProductType
All checks were successful
Build Docker Image / build (push) Successful in 1m16s
All checks were successful
Build Docker Image / build (push) Successful in 1m16s
This commit is contained in:
@@ -95,6 +95,23 @@ class ProductType(graphene.ObjectType):
|
||||
"""Unique product from offers."""
|
||||
uuid = graphene.String()
|
||||
name = graphene.String()
|
||||
offers_count = graphene.Int(description="Number of offers for this product")
|
||||
|
||||
def resolve_offers_count(self, info):
|
||||
db = get_db()
|
||||
aql = """
|
||||
FOR node IN nodes
|
||||
FILTER node.node_type == 'offer'
|
||||
FILTER node.product_uuid == @product_uuid
|
||||
COLLECT WITH COUNT INTO length
|
||||
RETURN length
|
||||
"""
|
||||
try:
|
||||
cursor = db.aql.execute(aql, bind_vars={'product_uuid': self.uuid})
|
||||
return next(cursor, 0)
|
||||
except Exception as e:
|
||||
logger.error("Error counting offers for product %s: %s", self.uuid, e)
|
||||
return 0
|
||||
|
||||
|
||||
class SupplierType(graphene.ObjectType):
|
||||
|
||||
Reference in New Issue
Block a user