Почему я не могу получить атрибуты участника, который прикреплен к активу? - PullRequest
0 голосов
/ 07 января 2019

Я хочу обновить актив. Для этого я хочу проверить, что только пользователь, который создал его (здесь: IssuePhysician), может обновить его. Проблема: я могу получить "itemToUpdate.issueingPhysician", но "itemToUpdate.issueingPhysician.userId" не определен.

Чтобы проиллюстрировать это, я поместил сообщение об ошибке в свой код (см. Ниже) и протестировал код в Composer Playground. Вернуло:

"Error: Only the physician who issued the prescription can change it. The current participant is: 1772 But the issueing Physican has userId: undefined The Issueing Physician is:Relationship {id=org.[...].participant.Physician#1772} His name is: undefined"

Версия Fabric - это hlfv12. В целях тестирования я дал всем участникам права администратора.

JS-код для транзакции:

/**
* Update a prescription.
* @param {org.[..].UpdatePrescription} transaction
* @transaction
*/
async function processUpdatingOfPrescription(transaction) {
     var prescriptionItemAssetRegistry = await getAssetRegistry('org.[..].Prescription');
     var itemToUpdate = await prescriptionItemAssetRegistry.get(transaction.recordId);
     if (getCurrentParticipant().userId == itemToUpdate.issueingPhysician.userId && itemToUpdate.status !== 'DELETED') {
     // [...]
     }
     else { // only to demonstrate that it is the same user:
         throw new Error('Only the physician who issued the prescription can change it. The current participant is: ' + getCurrentParticipant().userId + 
                    ' But the issueing Physican has userId: ' + itemToUpdate.issueingPhysician.userId + 'The itemToUpdate is:' + itemToUpdate.issueingPhysician)
}

}

Актив в cto-файле:

asset Prescription identified by recordId {
  o String recordId
  o String prescribedDrug
  --> Physician issueingPhysician
 }

Пользователь (= врач) В cto-файле:

participant Physician identified by userId {
  o String userId
  o String firstName
  o String lastName
}

Транзакция в cto-файле:

transaction UpdatePrescription {
  o String recordId
}

Я хотел бы получить значение для "itemToUpdate.issueingPhysician.userId".

1 Ответ

0 голосов
/ 07 января 2019

Когда вы получаете Актив, вы должны сами «разрешить» отношения (itemToUpdate.issueingPhysician.userId). См. Ответ Функция AssetRegistry.get не возвращает полный объект в Hyperledger Composer для получения дополнительной информации и отслеживания связанных проблем и статуса в Composer там.

Для сравнения идентификаторов - лучше всего использовать getIdentifier(), чтобы получить единичный идентификатор каждого экземпляра ресурса, для правильного сравнения самих идентификаторов:

попробовать:

"NS" ниже - это "org.acme" в моем сценарии.

async function processUpdatingOfPrescription(transaction) {
     var prescriptionItemAssetRegistry = await getAssetRegistry(NS + '.Prescription');
     var itemToUpdate = await prescriptionItemAssetRegistry.get(transaction.recordId);
     console.log('participant is ' + getCurrentParticipant().getIdentifier() );
     if (getCurrentParticipant().getIdentifier() == itemToUpdate.issueingPhysician.getIdentifier() && itemToUpdate.status !== 'DELETED') {
        console.log("yes they match !! ");
     }
     else { // only to demonstrate that it is the same user:
         throw new Error('Only the physician who issued the prescription can change it. The current participant is: ' + getCurrentParticipant().getIdentifier() + 
                    ' But the issueing Physican has userId: ' + itemToUpdate.issueingPhysician.getIdentifier() + 'The itemToUpdate is:' + itemToUpdate.issueingPhysician);
     }
}
...