如果我在.cto文件中有一个简单的枚举,比如:
enum STATUS {
o ACTIVE
o INACTIVE
}和用户
participant User identified by name{
o String name
o STATUS status
}如何在如下函数中检查状态:
transaction isActive {
o User user
}在logic.js文件中,我会有类似这样的代码:
return getParicipantRegistry(NS + '.User'){
.then(function(userRegistry) {
var u = userRegistry.get(user.name)
if (u.isActive == 'ACTIVE')
//some code
})我的情况稍微复杂一些(枚举有6种类型),但我试图简化它,使逻辑保持一致。
发布于 2018-08-25 14:01:35
尝尝这个。
将事务中的用户更改为关系
transaction isActive{
-->User user
}现在在logic.js中,您可以获得用户的状态,如下所示
/**
* checkStatus
* @param {org.test.isActive} checkStatus // use your namespace instead of org.test
* @transaction
*/
function checkStatus(txParams){
// txParams are the parameters given when the transaction is submitted
// you can access user details by txParams.user
if(txParams.user.status == "ACTIVE"){
// do something
}
// then you can update the user by
return getParticipantRegistry(NS+'.User').then(function(userRegistry){
// or you can also check status directly here and do something
return userRegistry.update(txParams.user)
})
}https://stackoverflow.com/questions/52012315
复制相似问题