serverlesspub / some-like-it-hot-delivery

6 stars 7 forks source link

order status doesn't change #2

Open ghost opened 3 years ago

ghost commented 3 years ago

Hi. I've wrote all the code from your book from chapter 4 and everything works well except changing order status by your api.

That's a code of the create-order handler:

`
create: req => {

if (!req.body || !req.body.pizzaId || !req.body.address) {

  throw new Error("To order pizza please provide pizza type " +
    "and address where pizza should be delivered");

} else {

  let deliveryUrl = "https://some-like-it-hot.effortless-serverless.com/delivery";

  let webhookUrl = "https://9z0y8x3sfj.execute-api.eu-central-1.amazonaws.com/latest/orders/updateStatus";

  let delivery = {

    pickupTime: "15.34pm",
    pickupAddress: "Pizzaeria Address",
    deliveryAddress: req.body.address,
    webhookUrl

  };

  return fetch(deliveryUrl, {

    method: "POST",
    body: JSON.stringify(delivery),
    headers: {

      "Authorization": "aunt-marias-pizzeria-1234567890",
      "Content-Type": "application/json"

    }

  })

    .then(res => res.json())

    .then(res => {

      return docClient.put({

        TableName: "orders",

        Item: {

          id: res.deliveryId,
          pizzaId: req.body.pizzaId,
          address: req.body.address,
          status: "pending"

        }

      })

      .promise()

    })

    .catch(error => {

      throw error;

    })

}

}`

That's a code of update-deliver-status: ` updateStatus: req => {

if (!req.body || !req.body.deliveryId || !req.body.status) {

  throw new Error("Status and delivery ID are required");

} else {

  return docClient.update({

    TableName: "orders",
    Key: { id: req.body.deliveryId },

    UpdateExpression: "set #status = :s",

    ExpressionAttributeValues: {

      ":s": req.body.status

    },

    ExpressionAttributeNames: {

      "#status": "status"

    }

  })

    .promise()

    .then(() => {})

    .catch(error => {

      throw error;

    })

}

}`

What really strange is that create-handler works okay, and you can even change status manually: curl -i -H "Content-Type: application/json" -X POST -d '{"deliveryId": "b2902e2f-1d53-4dae-a497-b6f78b299209", "status": "delivered"}' https://9z0y8x3sfj.execute-api.eu-central-1.amazonaws.com/latest/orders/updateStatus

So i guess something wrong with timing on the side of the api, you can check the result of the top curl on that path: https://9z0y8x3sfj.execute-api.eu-central-1.amazonaws.com/latest/orders

IlyaLytvynov commented 3 years ago

Also faced with this issue, @simalexan check if everything works well with api, workaround for me create own version of delivery service

rolasotelo commented 2 years ago

Same problem here. It looks like during last change to notify-delivery.js, 'webhook' was changed for 'webhookUrl', except for line 37 were it was kept as 'webhook'. Sorry @simalexan is there any possibility this can be fixed.

stojanovic commented 2 years ago

I'll take a look at that in the next day or two. Thanks for reporting the issue.