Code Monkey home page Code Monkey logo

some-like-it-hot-delivery's People

Contributors

simalexan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

some-like-it-hot-delivery's Issues

order status doesn't change

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.