Я хочу обновить актив. Для этого я хочу проверить, что только пользователь, который создал его (здесь: 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".