mosh-hamedani / vidly-api-node

309 stars 285 forks source link

Multiple returns issue on /api/returns #31

Closed SaeedEsk closed 4 years ago

SaeedEsk commented 4 years ago

1- user returns a rental and rental fee is calculated. 2-same user rents the same movie but in a different timestamp. 3-rentals.lookup() fails to distinguish between newly added rental(same movie) and the processed rental -->exp: i have watched matrix 2 for almost 5 times :D

SaeedEsk commented 4 years ago

First time mentioning an issue and answering it! :D you should query for latest rental created for specified customer and movie and then calculate the rental

const service = await rentals.findOne({ 'customer._id': req.body.customerId, 'table._id': req.body.tableId }).sort({_id:-1}).limit(1);