fetchEntityAggregateScorefromChain
fetchEntityAggregateScorefromChain(
entity
,ratingType
?):Promise
<IAggregateScore
[] |null
>
Fetches and aggregates scores for a specific entity from the blockchain.
This asynchronous function retrieves aggregate score data for a given entity from the blockchain. If a specific rating type is provided, it fetches the aggregate score for that rating type. Otherwise, it fetches aggregate scores across all rating types. The function decodes the retrieved data into a readable and structured format (IAggregateScore). This function is crucial for analyzing and presenting an overview of how an entity is rated across different parameters or overall.
Parameters
• entity: string
The identifier of the entity for which aggregate scores are to be fetched.
• ratingType?: RatingTypeOf
(Optional) The specific rating type to fetch the aggregate score for.
Returns
Promise
<IAggregateScore
[] | null
>
- A promise that resolves to an array of aggregate score objects, or null if no data is found.
Example
// Example usage of the function to fetch aggregate scores for a specific entity and rating typeconst entityId = 'entity123';const ratingType = RatingTypeOf.overall;
fetchEntityAggregateScorefromChain(entityId, ratingType) .then(aggregateScores => { if (aggregateScores) { console.log('Aggregate Scores:', aggregateScores); } else { console.log('No aggregate scores found for the specified entity and rating type.'); } }) .catch(error => { console.error('Error fetching aggregate scores:', error); });