Просмотр исходного кода

Englische Kommentare bzw. Kommentare und Swagger nochmals erweitert

Leonard Schulz (Arbeit) 2 лет назад
Родитель
Сommit
004c079642
1 измененных файлов с 62 добавлено и 12 удалено
  1. 62 12
      backend_nodejs/wbs_rechner_express.js

+ 62 - 12
backend_nodejs/wbs_rechner_express.js

@@ -1,6 +1,6 @@
 const express = require('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
 const swaggerJsdoc = require('swagger-jsdoc');
@@ -12,7 +12,7 @@ const options = {
         info: {
             title: 'WBS RECHNER',
             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'],
@@ -25,7 +25,7 @@ app.use('/api', swaggerUi.serve, swaggerUi.setup(specs));
  * @swagger
  * /calculate:
  *   post:
- *     summary: Berechnet ob ein WBS vergeben werden kann
+ *     summary: Calculates whether a WBS can be granted based on the provided incomes
  *     requestBody:
  *       required: true
  *       content:
@@ -67,7 +67,7 @@ app.use('/api', swaggerUi.serve, swaggerUi.setup(specs));
  *                       advertisingCosts: 0
  *     responses:
  *       200:
- *         description: Success
+ *         description: WBS calculation result
  *         content:
  *           application/json:
  *             schema:
@@ -75,8 +75,21 @@ app.use('/api', swaggerUi.serve, swaggerUi.setup(specs));
  *               properties:
  *                 wbsGranted:
  *                   type: boolean
+ *       400:
+ *         description: Bad Request
+ *       500:
+ *         description: Internal Server Error
  */
 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;
     const persons = req.body.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 wbsGranted = totalIncome <= maxIncome;
 
@@ -98,10 +111,10 @@ app.post('/calculate', (req, res) => {
  * @swagger
  * /frequencies:
  *   get:
- *     summary: Gibt alle möglichen Frequenzen der Einkommen zurück. 
+ *     summary: Retrieves all possible frequencies of income
  *     responses:
  *       200:
- *         description: Success
+ *         description: An array of frequency objects
  *         content:
  *           application/json:
  *             schema:
@@ -113,15 +126,33 @@ app.post('/calculate', (req, res) => {
  *                     type: number
  *                   description:
  *                     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) => {
+    /**
+     * 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 = [
         { value: 365, description: 'täglich' },
         { value: 12, description: 'monatlich' },
         { value: 4, description: 'vierteljährlich' },
         { value: 1, description: 'jährlich' }
-        //usw...
+        // etc...
     ];
     res.send(frequencies);
 });
@@ -130,10 +161,10 @@ app.get('/frequencies', (req, res) => {
  * @swagger
  * /types:
  *   get:
- *     summary: Gibt alle Typen der Einkommen zurück.
+ *     summary: Retrieves all types of income
  *     responses:
  *       200:
- *         description: Success
+ *         description: An array of income type objects
  *         content:
  *           application/json:
  *             schema:
@@ -145,14 +176,33 @@ app.get('/frequencies', (req, res) => {
  *                     type: string
  *                   description:
  *                     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) => {
+    /**
+     * 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 = [
         { value: 'work', description: 'als Arbeitnehmer' },
         { value: 'pensioner', description: 'als Rentner' },
         { value: 'social', description: 'Einnahme aus Sozialeistungen' },
         { value: 'entertains', description: 'Unterhalt' }
-        //usw...
+        // etc...
     ];
     res.send(types);
 });