Skip to content

Instantly share code, notes, and snippets.

@Dakuan
Last active January 8, 2018 12:57
Show Gist options
  • Save Dakuan/90303700c151d5a4371ee2135f73101c to your computer and use it in GitHub Desktop.
Save Dakuan/90303700c151d5a4371ee2135f73101c to your computer and use it in GitHub Desktop.
const express = require("express")
const request = require("request-promise")
const app = express()
const addExpectedDate = async invoice => {
try {
const { expectedDate } = await request(`${process.env.EXPECTED_DATE_URI}/api/expected-date/${invoice.id}`, {
json: true
})
return Object.assign({}, invoice, { expectedDate })
} catch (e) {
console.log(`failed to add expected date ${e}`)
return invoice
}
}
app.get("/api/invoices/:id", async (req, res, next) => {
try {
const id = parseInt(req.params.id)
const invoice = await addExpectedDate({
id: id,
ref: `INV-${id}`,
amount: id * 100,
balance: (id * 100) - 10,
ccy: "GBP"
})
res.json(invoice)
} catch (error) {
next(error)
}
})
const port = process.env.PORT || 8080
app.listen(port, () => {
console.log(`expected_date_svc listening on ${port}`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment