|
@@ -1,6 +1,6 @@
|
|
|
const express = require('express');
|
|
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()); // for parsing JSON data
|
|
|
|
|
|
|
|
// Swagger Setup
|
|
// Swagger Setup
|
|
|
const swaggerJsdoc = require('swagger-jsdoc');
|
|
const swaggerJsdoc = require('swagger-jsdoc');
|
|
@@ -12,7 +12,7 @@ const options = {
|
|
|
info: {
|
|
info: {
|
|
|
title: 'WBS RECHNER',
|
|
title: 'WBS RECHNER',
|
|
|
version: '1.0.0',
|
|
version: '1.0.0',
|
|
|
- description: 'Eine API für die Berechnung des Gesamteinkommens und die Gewährung von WBS.',
|
|
|
|
|
|
|
+ description: 'An API for calculating total income and granting WBS.',
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
apis: ['wbs_rechner_express.js'],
|
|
apis: ['wbs_rechner_express.js'],
|
|
@@ -25,7 +25,7 @@ app.use('/api', swaggerUi.serve, swaggerUi.setup(specs));
|
|
|
* @swagger
|
|
* @swagger
|
|
|
* /calculate:
|
|
* /calculate:
|
|
|
* post:
|
|
* post:
|
|
|
- * summary: Berechnet ob ein WBS vergeben werden kann
|
|
|
|
|
|
|
+ * summary: Calculates whether a WBS can be granted based on the provided incomes
|
|
|
* requestBody:
|
|
* requestBody:
|
|
|
* required: true
|
|
* required: true
|
|
|
* content:
|
|
* content:
|
|
@@ -67,7 +67,7 @@ app.use('/api', swaggerUi.serve, swaggerUi.setup(specs));
|
|
|
* advertisingCosts: 0
|
|
* advertisingCosts: 0
|
|
|
* responses:
|
|
* responses:
|
|
|
* 200:
|
|
* 200:
|
|
|
- * description: Success
|
|
|
|
|
|
|
+ * description: WBS calculation result
|
|
|
* content:
|
|
* content:
|
|
|
* application/json:
|
|
* application/json:
|
|
|
* schema:
|
|
* schema:
|
|
@@ -75,8 +75,21 @@ app.use('/api', swaggerUi.serve, swaggerUi.setup(specs));
|
|
|
* properties:
|
|
* properties:
|
|
|
* wbsGranted:
|
|
* wbsGranted:
|
|
|
* type: boolean
|
|
* type: boolean
|
|
|
|
|
+ * 400:
|
|
|
|
|
+ * description: Bad Request
|
|
|
|
|
+ * 500:
|
|
|
|
|
+ * description: Internal Server Error
|
|
|
*/
|
|
*/
|
|
|
app.post('/calculate', (req, res) => {
|
|
app.post('/calculate', (req, res) => {
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Calculates whether a WBS can be granted based on the provided incomes.
|
|
|
|
|
+ * @param {object[]} persons - An array of persons.
|
|
|
|
|
+ * @param {object[]} persons.incomes - An array of incomes for each person.
|
|
|
|
|
+ * @param {number} persons.incomes[].amount - The amount of income.
|
|
|
|
|
+ * @param {number} persons.incomes[].frequency - The frequency of income.
|
|
|
|
|
+ * @param {number} persons.incomes[].advertisingCosts - The advertising costs for the income.
|
|
|
|
|
+ * @returns {object} - The result object containing the wbsGranted property.
|
|
|
|
|
+ */
|
|
|
let totalIncome = 0;
|
|
let totalIncome = 0;
|
|
|
const persons = req.body.persons;
|
|
const persons = req.body.persons;
|
|
|
for (const person of persons) {
|
|
for (const person of persons) {
|
|
@@ -87,7 +100,7 @@ app.post('/calculate', (req, res) => {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- //Beispiel Berechnung entspricht nicht der WBS Berechnung
|
|
|
|
|
|
|
+ // Example calculation does not correspond to the WBS calculation
|
|
|
let maxIncome = persons.length * 12000;
|
|
let maxIncome = persons.length * 12000;
|
|
|
let wbsGranted = totalIncome <= maxIncome;
|
|
let wbsGranted = totalIncome <= maxIncome;
|
|
|
|
|
|
|
@@ -98,10 +111,10 @@ app.post('/calculate', (req, res) => {
|
|
|
* @swagger
|
|
* @swagger
|
|
|
* /frequencies:
|
|
* /frequencies:
|
|
|
* get:
|
|
* get:
|
|
|
- * summary: Gibt alle möglichen Frequenzen der Einkommen zurück.
|
|
|
|
|
|
|
+ * summary: Retrieves all possible frequencies of income
|
|
|
* responses:
|
|
* responses:
|
|
|
* 200:
|
|
* 200:
|
|
|
- * description: Success
|
|
|
|
|
|
|
+ * description: An array of frequency objects
|
|
|
* content:
|
|
* content:
|
|
|
* application/json:
|
|
* application/json:
|
|
|
* schema:
|
|
* schema:
|
|
@@ -113,15 +126,33 @@ app.post('/calculate', (req, res) => {
|
|
|
* type: number
|
|
* type: number
|
|
|
* description:
|
|
* description:
|
|
|
* type: string
|
|
* type: string
|
|
|
|
|
+ * example:
|
|
|
|
|
+ * - value: 365
|
|
|
|
|
+ * description: "täglich"
|
|
|
|
|
+ * - value: 12
|
|
|
|
|
+ * description: "monatlich"
|
|
|
|
|
+ * - value: 4
|
|
|
|
|
+ * description: "vierteljährlich"
|
|
|
|
|
+ * - value: 1
|
|
|
|
|
+ * description: "jährlich"
|
|
|
|
|
+ * 400:
|
|
|
|
|
+ * description: Bad Request
|
|
|
|
|
+ * 500:
|
|
|
|
|
+ * description: Internal Server Error
|
|
|
*/
|
|
*/
|
|
|
-
|
|
|
|
|
app.get('/frequencies', (req, res) => {
|
|
app.get('/frequencies', (req, res) => {
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Retrieves all possible frequencies of income.
|
|
|
|
|
+ * @returns {object[]} - An array of frequency objects.
|
|
|
|
|
+ * @property {number} value - The value of the frequency.
|
|
|
|
|
+ * @property {string} description - The description of the frequency.
|
|
|
|
|
+ */
|
|
|
const frequencies = [
|
|
const frequencies = [
|
|
|
{ value: 365, description: 'täglich' },
|
|
{ value: 365, description: 'täglich' },
|
|
|
{ value: 12, description: 'monatlich' },
|
|
{ value: 12, description: 'monatlich' },
|
|
|
{ value: 4, description: 'vierteljährlich' },
|
|
{ value: 4, description: 'vierteljährlich' },
|
|
|
{ value: 1, description: 'jährlich' }
|
|
{ value: 1, description: 'jährlich' }
|
|
|
- //usw...
|
|
|
|
|
|
|
+ // etc...
|
|
|
];
|
|
];
|
|
|
res.send(frequencies);
|
|
res.send(frequencies);
|
|
|
});
|
|
});
|
|
@@ -130,10 +161,10 @@ app.get('/frequencies', (req, res) => {
|
|
|
* @swagger
|
|
* @swagger
|
|
|
* /types:
|
|
* /types:
|
|
|
* get:
|
|
* get:
|
|
|
- * summary: Gibt alle Typen der Einkommen zurück.
|
|
|
|
|
|
|
+ * summary: Retrieves all types of income
|
|
|
* responses:
|
|
* responses:
|
|
|
* 200:
|
|
* 200:
|
|
|
- * description: Success
|
|
|
|
|
|
|
+ * description: An array of income type objects
|
|
|
* content:
|
|
* content:
|
|
|
* application/json:
|
|
* application/json:
|
|
|
* schema:
|
|
* schema:
|
|
@@ -145,14 +176,33 @@ app.get('/frequencies', (req, res) => {
|
|
|
* type: string
|
|
* type: string
|
|
|
* description:
|
|
* description:
|
|
|
* type: string
|
|
* type: string
|
|
|
|
|
+ * example:
|
|
|
|
|
+ * - value: 'work'
|
|
|
|
|
+ * description: 'als Arbeitnehmer'
|
|
|
|
|
+ * - value: 'pensioner'
|
|
|
|
|
+ * description: 'als Rentner'
|
|
|
|
|
+ * - value: 'social'
|
|
|
|
|
+ * description: 'Einnahme aus Sozialeistungen'
|
|
|
|
|
+ * - value: 'entertains'
|
|
|
|
|
+ * description: 'Unterhalt'
|
|
|
|
|
+ * 400:
|
|
|
|
|
+ * description: Bad Request
|
|
|
|
|
+ * 500:
|
|
|
|
|
+ * description: Internal Server Error
|
|
|
*/
|
|
*/
|
|
|
app.get('/types', (req, res) => {
|
|
app.get('/types', (req, res) => {
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Retrieves all types of income.
|
|
|
|
|
+ * @returns {object[]} - An array of income type objects.
|
|
|
|
|
+ * @property {string} value - The value of the income type.
|
|
|
|
|
+ * @property {string} description - The description of the income type.
|
|
|
|
|
+ */
|
|
|
const types = [
|
|
const types = [
|
|
|
{ value: 'work', description: 'als Arbeitnehmer' },
|
|
{ value: 'work', description: 'als Arbeitnehmer' },
|
|
|
{ value: 'pensioner', description: 'als Rentner' },
|
|
{ value: 'pensioner', description: 'als Rentner' },
|
|
|
{ value: 'social', description: 'Einnahme aus Sozialeistungen' },
|
|
{ value: 'social', description: 'Einnahme aus Sozialeistungen' },
|
|
|
{ value: 'entertains', description: 'Unterhalt' }
|
|
{ value: 'entertains', description: 'Unterhalt' }
|
|
|
- //usw...
|
|
|
|
|
|
|
+ // etc...
|
|
|
];
|
|
];
|
|
|
res.send(types);
|
|
res.send(types);
|
|
|
});
|
|
});
|