为了让函数正常运行,你必须
return
一个承诺,在你的情况下
Promise.all
:
async function findAdditionals(context) {
const { result, app } = context;
let newResultData = result.data.map(async pr => {
let includedRecords = await app.service('propertyadds').find({
query: {
property_id: pr.id
}
})
pr.additionals = includedRecords.map(e => e.additional_id);
return pr;
})
return Promise.all(newResultData).then(completed => {
return Object.assign({},context,{result: {
total: result.total,
limit: result.limit,
skip: result.skip,
data: completed
}})
});
}
然而,羽毛不会用这种方法做任何事情。只有方法
described in the service interface
将映射到REST端点。本文描述了对现有类的扩展
in the guide
还有
database adapter API
和扩展任何其他JavaScript类一样。
另一种选择是使用
hook
上
find
方法与集合
context.result
.