使用typescript“获取feathers聊天教程的错误消息”;错误:必须向';users.get';方法“;
我遵循feathers指南页面()上的feathers聊天教程,应用程序在其中一个测试中失败 **OBS:我正在使用typescript版本,但使用mongoose连接到MongoDB** 这是错误消息使用typescript“获取feathers聊天教程的错误消息”;错误:必须向';users.get';方法“;,typescript,feathersjs,Typescript,Feathersjs,我遵循feathers指南页面()上的feathers聊天教程,应用程序在其中一个测试中失败 **OBS:我正在使用typescript版本,但使用mongoose连接到MongoDB** 这是错误消息 1) 'messages' service creates and processes message, adds user information: Error: An id must be provided to the 'users.get' method at Object.
1) 'messages' service
creates and processes message, adds user information:
Error: An id must be provided to the 'users.get' method
at Object.validate (node_modules/@feathersjs/feathers/lib/hooks/base.js:23:11)
at /Users/fabriciobracht/Documents/cpsc2650/feathers-chat/node_modules/@feathersjs/commons/src/hooks.ts:132:47
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at addUser (src/hooks/populate-user.ts:13:20)
at Object.<anonymous> (src/hooks/populate-user.ts:28:24)
at Context.<anonymous> (test/services/messages.test.ts:20:21)
哪些调用填充-user.ts
export default (): Hook => {
return async (context: HookContext) => {
// Get `app`, `method`, `params` and `result` from the hook context
const { app, method, result, params } = context;
// Function that adds the user to a single message object
const addUser = async (message: any) => {
// Get the user based on their id, pass the `params` along so
// that we get a safe version of the user data
const user = await app.service('users').get(message.userId, params);
// Merge the message content to include the `user` object
return {
...message,
user
};
};
// In a find method we need to process the entire page
if (method === 'find') {
// Map all data to include the `user` information
context.result.data = await Promise.all(result.data.map(addUser));
} else {
// Otherwise just update the single result
context.result = await addUser(result);
}
return context;
};
}
但这就是我迷路的地方。
有人能解释一下这件事吗?
Thx
export default (): Hook => {
return async (context: HookContext) => {
// Get `app`, `method`, `params` and `result` from the hook context
const { app, method, result, params } = context;
// Function that adds the user to a single message object
const addUser = async (message: any) => {
// Get the user based on their id, pass the `params` along so
// that we get a safe version of the user data
const user = await app.service('users').get(message.userId, params);
// Merge the message content to include the `user` object
return {
...message,
user
};
};
// In a find method we need to process the entire page
if (method === 'find') {
// Map all data to include the `user` information
context.result.data = await Promise.all(result.data.map(addUser));
} else {
// Otherwise just update the single result
context.result = await addUser(result);
}
return context;
};
}