Created
February 19, 2019 23:57
-
-
Save carlosmaniero/871ab6436db750032867b58e43cda6e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.post('/customers/:customerId/orders/', (req, res) => { | |
if (req.body.items.length === 0) { | |
res.status(400).end() | |
} else { | |
MongoClient.connect(url, function (err, client) { | |
if (err) { | |
console.error(err) | |
} | |
const db = client.db(dbName) | |
const collection = db.collection('orders') | |
const order = req.body | |
order.customerId = req.params.customerId | |
collection.insertOne(order, function (err, result) { | |
if (err) { | |
console.error(err) | |
} | |
res.send(result.ops[0]) | |
}) | |
client.close() | |
}) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment