|
@@ -2,7 +2,61 @@ const express = require('express');
|
|
|
const app = express();
|
|
const app = express();
|
|
|
app.use(express.json()); //für das Parsing von JSON-Daten
|
|
app.use(express.json()); //für das Parsing von JSON-Daten
|
|
|
|
|
|
|
|
|
|
+// Swagger Setup
|
|
|
|
|
+const swaggerJsdoc = require('swagger-jsdoc');
|
|
|
|
|
+const swaggerUi = require('swagger-ui-express');
|
|
|
|
|
|
|
|
|
|
+const options = {
|
|
|
|
|
+ definition: {
|
|
|
|
|
+ openapi: '3.0.0',
|
|
|
|
|
+ info: {
|
|
|
|
|
+ title: 'WBS RECHNER',
|
|
|
|
|
+ version: '1.0.0',
|
|
|
|
|
+ description: 'Eine API für die Berechnung des Gesamteinkommens und die Gewährung von WBS.',
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ apis: ['app.js'],
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+const specs = swaggerJsdoc(options);
|
|
|
|
|
+app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(specs));
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @swagger
|
|
|
|
|
+ * /calculate:
|
|
|
|
|
+ * post:
|
|
|
|
|
+ * summary: Calculates the total income and determines if WBS is granted.
|
|
|
|
|
+ * requestBody:
|
|
|
|
|
+ * required: true
|
|
|
|
|
+ * content:
|
|
|
|
|
+ * application/json:
|
|
|
|
|
+ * schema:
|
|
|
|
|
+ * type: array
|
|
|
|
|
+ * items:
|
|
|
|
|
+ * type: object
|
|
|
|
|
+ * properties:
|
|
|
|
|
+ * incomes:
|
|
|
|
|
+ * type: array
|
|
|
|
|
+ * items:
|
|
|
|
|
+ * type: object
|
|
|
|
|
+ * properties:
|
|
|
|
|
+ * amount:
|
|
|
|
|
+ * type: number
|
|
|
|
|
+ * frequency:
|
|
|
|
|
+ * type: number
|
|
|
|
|
+ * advertisingCosts:
|
|
|
|
|
+ * type: number
|
|
|
|
|
+ * responses:
|
|
|
|
|
+ * 200:
|
|
|
|
|
+ * description: Success
|
|
|
|
|
+ * content:
|
|
|
|
|
+ * application/json:
|
|
|
|
|
+ * schema:
|
|
|
|
|
+ * type: object
|
|
|
|
|
+ * properties:
|
|
|
|
|
+ * wbsGranted:
|
|
|
|
|
+ * type: boolean
|
|
|
|
|
+ */
|
|
|
app.post('/calculate', (req, res) => {
|
|
app.post('/calculate', (req, res) => {
|
|
|
let totalIncome = 0;
|
|
let totalIncome = 0;
|
|
|
const persons = req.body;
|
|
const persons = req.body;
|
|
@@ -21,6 +75,27 @@ app.post('/calculate', (req, res) => {
|
|
|
res.send({ wbsGranted: wbsGranted });
|
|
res.send({ wbsGranted: wbsGranted });
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * @swagger
|
|
|
|
|
+ * /frequencies:
|
|
|
|
|
+ * get:
|
|
|
|
|
+ * summary: Returns the available income frequencies.
|
|
|
|
|
+ * responses:
|
|
|
|
|
+ * 200:
|
|
|
|
|
+ * description: Success
|
|
|
|
|
+ * content:
|
|
|
|
|
+ * application/json:
|
|
|
|
|
+ * schema:
|
|
|
|
|
+ * type: array
|
|
|
|
|
+ * items:
|
|
|
|
|
+ * type: object
|
|
|
|
|
+ * properties:
|
|
|
|
|
+ * value:
|
|
|
|
|
+ * type: number
|
|
|
|
|
+ * description:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
app.get('/frequencies', (req, res) => {
|
|
app.get('/frequencies', (req, res) => {
|
|
|
const frequencies = [
|
|
const frequencies = [
|
|
|
{ value: 365, description: 'täglich' },
|
|
{ value: 365, description: 'täglich' },
|
|
@@ -32,6 +107,26 @@ app.get('/frequencies', (req, res) => {
|
|
|
res.send(frequencies);
|
|
res.send(frequencies);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * @swagger
|
|
|
|
|
+ * /types:
|
|
|
|
|
+ * get:
|
|
|
|
|
+ * summary: Returns the available income types.
|
|
|
|
|
+ * responses:
|
|
|
|
|
+ * 200:
|
|
|
|
|
+ * description: Success
|
|
|
|
|
+ * content:
|
|
|
|
|
+ * application/json:
|
|
|
|
|
+ * schema:
|
|
|
|
|
+ * type: array
|
|
|
|
|
+ * items:
|
|
|
|
|
+ * type: object
|
|
|
|
|
+ * properties:
|
|
|
|
|
+ * value:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ * description:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ */
|
|
|
app.get('/types', (req, res) => {
|
|
app.get('/types', (req, res) => {
|
|
|
const types = [
|
|
const types = [
|
|
|
{ value: 'work', description: 'als Arbeitnehmer' },
|
|
{ value: 'work', description: 'als Arbeitnehmer' },
|
|
@@ -40,7 +135,7 @@ app.get('/types', (req, res) => {
|
|
|
{ value: 'entertains', description: 'Unterhalt' }
|
|
{ value: 'entertains', description: 'Unterhalt' }
|
|
|
//usw...
|
|
//usw...
|
|
|
];
|
|
];
|
|
|
- res.send(frequencies);
|
|
|
|
|
|
|
+ res.send(types);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
const port = process.env.PORT || 3000;
|
|
const port = process.env.PORT || 3000;
|