import { ErrorUnexpectedResult , Organization , Permission , PermissionData , } from '@aragon/connect-core' ; import { QueryResult } from '../types' ; export function parsePermissions ( result , organization ) { const permissions = result ?. data ?. organization ?. permissions ; if ( ! Array . isArray ( permissions ) ) { throw new ErrorUnexpectedResult ( 'Unable to parse permissions.' ) ; } const datas = permissions . map ( ( permission ) : PermissionData => ( { appAddress : permission ?. appAddress , allowed : permission ?. allowed , granteeAddress : permission ?. granteeAddress , params : permission ?. params ?. map ?. ( ( param ) => ( { argumentId : param ?. argumentId , operationType : param ?. operationType , argumentValue : param ?. argumentValue , } ) ) || [ ] , roleHash : permission ?. roleHash , } ) ) ; const allowedPermissions = datas . filter ( ( data ) => data . allowed ) ; return allowedPermissions . map ( ( data ) => { return new Permission ( data , organization ) ; } ) ; }