You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 1.0 KiB

7 jaren geleden
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. var bodyParser = require('body-parser')
  2. var express = require('express')
  3. var app = express()
  4. var input
  5. app.use(bodyParser.json({
  6. limit: '100mb',
  7. type: 'application/json'
  8. }))
  9. app.get('/help', function (req, res) {
  10. res.send('https://github.com/binhonglee/Breakups')
  11. })
  12. app.post('/total', function (req, res) {
  13. input = req.body
  14. var toReturn = { 'total': 0 }
  15. toReturn.total = total(input.users)
  16. res.json(toReturn)
  17. })
  18. app.post('/perPerson', function (req, res) {
  19. input = req.body
  20. var toReturn = { 'perPerson': 0 }
  21. toReturn.perPerson = (total(input.users)) / input.users.length
  22. res.json(toReturn)
  23. })
  24. app.post('/oweChart', function (req, res) {
  25. input = req.body
  26. var perPerson = total(input.users) / input.users.length
  27. for (var i = 0; i < input.users.length; i++) {
  28. input.users[i].amount -= perPerson
  29. }
  30. res.json(input)
  31. })
  32. // app.listen(3000)
  33. app.listen(process.env.PORT)
  34. function total (input) {
  35. var total = 0
  36. for (var i = 0; i < input.length; i++) {
  37. total += input[i].amount
  38. }
  39. return total
  40. }