code: function listPolicyInstances ({ id, organizationId, type }, cb) {
        let promise = null
        if (typeof cb !== 'function') [promise, cb] = asyncify()
  
        Joi.validate({ id, organizationId, type }, validationRules.listPolicyInstances, function (err) {
          if (err) return cb(Boom.badRequest(err))
  
          const sqlQuery = SQL`          
            SELECT entity_type, entity_id, policy_instance, variables, policy_id FROM
            (SELECT 'user' as entity_type, user_id as entity_id, variables, policy_instance, policy_id
            FROM user_policies
            WHERE policy_id = ${id}
            UNION
            SELECT 'team' as entity_type, team_id as entity_id, variables, policy_instance, policy_id
            FROM team_policies
            WHERE policy_id = ${id}
            UNION
            SELECT 'organization' as entity_type, org_id as entity_id, variables, policy_instance, policy_id
            FROM organization_policies
            WHERE policy_id = ${id}) as policy_instances
            INNER JOIN policies 
            ON policies.id = policy_instances.policy_id
          `
  
          if (type === 'shared') {
            sqlQuery.append(SQL` WHERE org_id is NULL`)
          } else {
            sqlQuery.append(SQL` WHERE org_id=${organizationId}`)
          }
          sqlQuery.append(SQL` ORDER BY entity_type, policy_instance`)
  
          db.query(sqlQuery, function (err, result) {
            if (err) return cb(Boom.badImplementation(err))
            if (result.rowCount === 0) return cb(null, [])
            return cb(null, result.rows.map(mapping.policy.instances))
          })
        })
        return promise
      }
docs: list policy instances in their respective entities
  
  @param  {Object}   params { id, organizationId, type } "type" is optional, defaults to organization policies
  @param  {Function} cb