Set node/edge property using aggregate function on connected edges/nodes

I am trying to set an edge attribute based on some aggregation of the values of its source and target nodes. I have tried many things but none seem to work, what I want is basically this

MATCH (s)-[r]-(t) SET r.new_property = avg(s.property, t.property)

same for min and max aggregations. I know the above query is syntactically incorrect, but is there a way to get the desired result?

I am also interested in setting a node property based on some aggreagtion of the connected relationships

MATCH (s)-[r]-() SET s.new_property = avg/min/max(r.property)

Please help!

I tried this and it works

CALL { MATCH (s)-[e]-() return s, avg(e.weight) as avg} WITH s.node_id as nid, avg MATCH (s {node_id: nid}) set s.new_prop = avg

Is there a better way to do so?

This should work:

MATCH (s)-[e]-() 
WITH 
  s, 
  avg(e.weight) as avg,
  min(e.weight) as min,
  max(e.weight) as max
SET 
  s.new_property_avg = avg,
  s.new_property_min = min,
  s.new_property_max = max