gpt4 book ai didi

javascript - 错误: Invalid or missing identifier for Type in namespace

转载 作者:行者123 更新时间:2023-12-03 02:32:36 26 4
gpt4 key购买 nike

当我尝试对从抽象基类 Assets 继承的 Assets 调用事务时,调用失败并显示 Error: Invalid or missing identifier for Type <type> in namespace <name.spa.ce>

user.cto

namespace com.aczire.alm.base.user

import com.aczire.alm.base.*

abstract participant User {
o String uid
o String title optional
o String firstName optional
o String lastName optional
o UserTransactionLogEntry[] logEntries
}

concept UserTransactionLogEntry {
//--> User modified_by
o String comment optional
o DateTime timestamp
}

abstract transaction UserTransaction {
o String comment
}

abstract event UserTransactionEvent {
o String comment
}

admin.cto

namespace com.aczire.alm.base.user.admin

import com.aczire.alm.base.*
import com.aczire.alm.base.user.*

participant Admin identified by uname extends User {
o String uname
}

abstract transaction AdminUserTransaction extends UserTransaction {
o Admin user
--> Admin modified_by
}

abstract event AdminUserTransactionEvent extends UserTransactionEvent {
--> Admin user
--> Admin modified_by
}

transaction CreateUser extends AdminUserTransaction {
}

admin.js

/**
* Create a User
* @param {com.aczire.alm.base.user.admin.CreateUser} createUser - the CreateUser transaction
* @transaction
*/
function createUser(newuser) {
console.log('createUser');

var factory = getFactory();
var NS_AU = 'com.aczire.alm.base.user.admin';

var user = factory.newResource(NS_AU, 'Admin', newuser.uname);
user.uid = newuser.uid;

// save the order
return getAssetRegistry(NS_AU)
.then(function (registry) {
return registry.add(user);
})
.then(function(){
var userCreatedEvent = factory.newEvent(NS_AU, 'UserCreatedEvent');
userCreatedEvent.user = user;
userCreatedEvent.comment = 'Created new admin user - ' + newuser.uname + '!';
emit(userCreatedEvent);
});
}

我尝试以用户、管理员身份将参数设置为TP;将交易参数移至基类作为 User 类型;将事务移动到基类等。但似乎没有任何作用。

这里继承的工作方式是否不同?

Composer Playground 中显示错误。 enter image description here

最佳答案

您的 admin.js 有一些问题。该错误是因为 Admin 是参与者,因此您必须 getParticipantRegistry() 而不是 Assetregistry,然后添加用户。此外,在您的模型文件 admin.cto 中,没有名为 UserCreatedEvent 的事件。因此,您首先需要将其添加到模型中,然后发出事件。要添加用户,请尝试更改为此。

    /**
* Create a User
* @param {com.aczire.alm.base.user.admin.CreateUser} createUser - the CreateUser transaction
* @transaction
*/
function createUser(newuser) {
console.log('createUser');
var NS_AU = 'com.aczire.alm.base.user.admin';
var factory = getFactory();

var testuser = factory.newResource(NS_AU, 'Admin', newuser.user.uname);
testuser.uid=newuser.user.uid
testuser.logEntries=newuser.user.logEntries
// save the order
return getParticipantRegistry('com.aczire.alm.base.user.admin.Admin')
.then(function (registry) {
return registry.add(testuser);
});
}

关于javascript - 错误: Invalid or missing identifier for Type in namespace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48671801/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com