简体   繁体   English

无法从prisma服务器得到响应

[英]can not get the response from the prisma server

exports.createRecipe =  (req, res, next) => {

  const rec = req.body
  for (let index = 0; index < rec.length; index++) {
    const element = rec[index];
    const name = element.name
    const description = element.description
    const imgUrl = element.imgUrl
    const ingredient = element.ingredient
     prisma.createRecipes({
      name: name,
      description: description,
      imgUrl: imgUrl,
      ingredients:{
        create: ingredient
      }
    })
    .then(response=>{
      console.log(response)
      res.json(response)
    }).catch(error=>{
      console.log(error)
    })

  }
  // res.status(200).json(recipes);
};

Above is my create recipe function.以上是我的创建配方功能。

Here is My route file这是我的路线文件

router.post('', RecipeController.createRecipe)

** I send this type of data from front end as application/json** ** 我从前端将这种类型的数据作为 application/json 发送**

[
{
name: 'MY first Recipe',
description: 'Test Recipe',
imgUrl: 'http://www.google.com'
ingredient: [{name: 'Apple', amount: '2'}, {name: 'Tomatoes', amount: '3'}]
},
{
name: 'MY first Recipe',
description: 'Test Recipe',
imgUrl: 'http://www.google.com'
ingredient: [{name: 'Apple', amount: '2'}, {name: 'Tomatoes', amount: '3'}]
},

]

But When want to create the recipe in the backend using createRecipes which prisma client provides i cant create the recipe can anybody help me please with this please i am stuck on this.但是,当想使用prisma 客户端提供的createRecipes 在后端创建配方时,我无法创建配方,任何人都可以帮我解决这个问题,请我坚持下去。

return prisma.mutation.createRecipes({ //u missed the mutation
   data: {                             // missed the data {...}
       name: name,
       description: description,
       imgUrl: imgUrl,
       ingredients:{
            create: {
               ingredient: ingredient   //ingredient to your "typefieldname"
            }
       }
   }
})

I never used: json(response), I return my result direct.我从来没有用过:json(response),我直接返回我的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM