wbs_rechner_express.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const express = require('express');
  2. const app = express();
  3. app.use(express.json()); //für das Parsing von JSON-Daten
  4. app.post('/calculate', (req, res) => {
  5. let totalIncome = 0;
  6. const persons = req.body;
  7. for (const person of persons) {
  8. for (const income of person.incomes) {
  9. let annualIncome = income.amount * income.frequency;
  10. annualIncome -= income.advertisingCosts;
  11. totalIncome += annualIncome;
  12. }
  13. }
  14. //Beispiel Berechnung entspricht nicht der WBS Berechnung
  15. let maxIncome = persons.length * 12000;
  16. let wbsGranted = maxIncome <= totalIncome;
  17. res.send({ wbsGranted: wbsGranted });
  18. });
  19. app.get('/frequencies', (req, res) => {
  20. const frequencies = [
  21. { value: 365, description: 'täglich' },
  22. { value: 12, description: 'monatlich' },
  23. { value: 4, description: 'vierteljährlich' },
  24. { value: 1, description: 'jährlich' }
  25. //usw...
  26. ];
  27. res.send(frequencies);
  28. });
  29. app.get('/types', (req, res) => {
  30. const types = [
  31. { value: 'work', description: 'als Arbeitnehmer' },
  32. { value: 'pensioner', description: 'als Rentner' },
  33. { value: 'social', description: 'Einnahme aus Sozialeistungen' },
  34. { value: 'entertains', description: 'Unterhalt' }
  35. //usw...
  36. ];
  37. res.send(frequencies);
  38. });
  39. const port = process.env.PORT || 3000;
  40. app.listen(port, () => console.log(`Server läuft auf Port ${port}...`));