如何使用trapi.js手动创建新的内容类型文档?

时间:2020-06-08 15:58:21

标签: strapi

我有一个内容类型用户,其中包含配置文件和地址,在前端,我有一个表格,其中包含配置文件,地址和用户的所有字段,并且发送的数据如下:

{
  user: {username: '', password:'', password2: ''},
  profile: { firstname: '', lastname: '' ...},
  address: {street: '', city: '', ...}
}

在控制器中,我想先创建配置文件,然后创建地址,然后将其链接到用户。

在控制器中:

module.exports = {
async create(ctx) {

    const profile = await strapi.services.profiles.create(ctx.request.body.profile);
    const addr = await strapi.services.profiles.create(ctx.request.body.address);
    const userObj = {}
    user.profile = profile;
    user.addr = addr
    userObj.username = ctx.request.body.username
    userObj.username = ctx.request.body.password
    const user = await strapi.services.user.create(userObj);
    return sanitizeEntity(entity, { model: strapi.models.user });
}

};

0 个答案:

没有答案