在 Strapi 中,每个用户定义的集合类型都有一个默认服务,允许创建/查找/更新/等。在相应的模型上。
例如,Strapi Controller 中的以下代码将使用给定数据更新账单收集类型:
await strapi.services.bill.update({id}, {verified: true, receipt_number})
但是没有服务用户 内置集合类型。我需要通过自定义 Controller 更改用户的 Angular 色。
最佳答案
好的。我找到了解决方案。我们可以修改或创建自定义服务,并从这里的核心服务实现中获得灵感:
https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-services
就我而言,我已将此方法添加到自定义服务中:
updateUserRole: async (user_id, role_id) => {
return await strapi.query('user', 'users-permissions').update({id: user_id}, {role: role_id});}
现在我可以像这样访问此服务:await strapi.services.customServiceName.updateUserRole(user_id, new_role)
关于javascript - 如何在 Strapi 中更新用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62631528/