Last active
February 12, 2017 20:24
-
-
Save crizstian/05898db671bd8cd469f8ad1cef3c3726 to your computer and use it in GitHub Desktop.
Example of an API
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
'use strict' | |
const status = require('http-status') | |
module.exports = ({repo}, app) => { | |
app.post('/payment/makePurchase', (req, res, next) => { | |
const {validate} = req.container.cradle | |
validate(req.body.paymentOrder, 'payment') | |
.then(payment => { | |
return repo.registerPurchase(payment) | |
}) | |
.then(paid => { | |
res.status(status.OK).json({paid}) | |
}) | |
.catch(next) | |
}) | |
app.get('/payment/getPurchaseById/:id', (req, res, next) => { | |
repo.getPurchaseById(req.params.id) | |
.then(payment => { | |
res.status(status.OK).json({payment}) | |
}) | |
.catch(next) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment