【问题标题】:how to create a Custom User in strapi.js如何在 Strapi.js 中创建自定义用户
【发布时间】:2020-09-27 20:52:19
【问题描述】:

我正在开发一个 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 时,它给了我一个错误。

你有什么建议吗?

【问题讨论】:

    标签: api koa strapi


    【解决方案1】:

    Refer
    创建用户查询应该是这样的。

    const user = await strapi.query('user', 'users-permissions').create(userObj);
    

    这样,您无需创建新的用户 API 并使用 Strapi 附带的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-24
      • 2023-03-06
      • 2019-03-31
      • 2016-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-25
      相关资源
      最近更新 更多