1

I am working on a strapi-app and I have 3 content-types: - User (the one that comes with strapi) - profile - Employee (has one User, has one Profile)

this is my code:

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;
  },

it's working but I created another user Controller/service and model because when I tried without creating a new user C/S/M it gave me an error.

Wny suggestions please?

Skalip
  • 43
  • 1
  • 8

1 Answers1

1

Refer
The create user query should be like this.

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

This way you need not create a new User API and use the one that comes with Strapi.

Prasanna Kumar
  • 368
  • 1
  • 5
  • 14