api - 如何在 Strapi.js 中创建自定义用户
问题描述
我正在开发一个 Strapi 应用程序,我有 3 种内容类型: - 用户(strapi 附带的那个) - 个人资料 - 员工(有一个用户,有一个个人资料)
这是我的代码:
async create(data, { files } = {}) {
const profileObj = data.profile
const employeeObj = {
salary_type: data.salarytype,
salary: data.salary
}
const userObj = data.user
profileObj.address = data.address
const user = await strapi.query('user').create(userObj);
const profile = await strapi.query('profile').create(profileObj);
const employee = await strapi.query('employee').create(employeeObj);
employee.user = user
employee.profile = profile
if (files) {
// automatically uploads the files based on the entry and the model
await strapi.entityService.uploadFiles(employee, files, {
model: 'profile',
});
return this.findOne({ id: employee.id });
}
return employee;
},
它正在工作,但我创建了另一个用户控制器/服务和模型,因为当我尝试不创建新用户 C/S/M 时,它给了我一个错误。
请问有什么建议吗?
解决方案
请参阅
创建用户查询应该是这样的。
const user = await strapi.query('user', 'users-permissions').create(userObj);
这样,您无需创建新的用户 API 并使用 Strapi 附带的用户 API。
推荐阅读
- python - Cs50财务表格填写错误时报错500
- python - 使用 pandas 创建具有行信息的类别
- flutter - 如何在 Flutter 的 AndroidView 或 UiKitView 中检测缩放和平移手势?
- c++ - 如何在 C++ STL 中实现具有三个键的映射?
- swift - MDC 在助手/计数器视图和边框之间添加
- aws-codepipeline - AWS codePipeline:去获取:未知版本 v1.0.0
- python - 两个文件Python中的列差异
- tensorflow2.0 - 如何在特定 GPU 上运行 TF2.0 代码
- webpack - 执行 npx webpack-dev-server,找不到模块
- java - 必须捕获或声明要抛出未报告的异常: