mosh-hamedani / vidly-api-node

309 stars 285 forks source link

One of the properties of customer `isGold` is not override in rentals api #38

Open CodeWithSouma opened 3 years ago

CodeWithSouma commented 3 years ago

One of the properties of customer isGold is not override in rentals api

When we call rental post route ( like this http://localhost:3000/api/rentals/) with given value

{
    "customerId":"5f6f53afb53731ef06d7c01e",
    "movieId":"5f6f5180b53731ef06d7c01c"
}

although our customer is Gold customer it is not assign in rental document it shows isGold:false .

{
    "_id": "5f6f55548ac0e2f2c6532571",
    "customer": {
        "isGold": false,
        "_id": "5f6f53afb53731ef06d7c01e",
        "name": "Soumadip Dey",
        "phone": "8768454982"
    },
    "movie": {
        "_id": "5f6f5180b53731ef06d7c01c",
        "title": "Ratsasant",
        "dailyRentalRate": 20
    },
    "dateOut": "2020-09-26T14:51:00.943Z",
    "__v": 0
}

It's happening for the rental schema's customer customer child schema's isGold default value

isGold: {
        type: Boolean,
        default: false
      }

sollution

We need to override isGold property in rental api's post route like this

 
customer: {
      _id: customer._id,
      name: customer.name, 
      phone: customer.phone,
      isGold:customer.isGold
    }