簡體   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);
};

以上是我的創建配方功能。

這是我的路線文件

router.post('', RecipeController.createRecipe)

** 我從前端將這種類型的數據作為 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'}]
},

]

但是,當想使用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"
            }
       }
   }
})

我從來沒有用過:json(response),我直接返回我的結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM