Forráskód Böngészése

Persons Extra Objekt in Json
sowie beispiel Request hinterlegt

Leonard Schulz (Arbeit) 2 éve
szülő
commit
1e241b51e5
1 módosított fájl, 42 hozzáadás és 16 törlés
  1. 42 16
      backend_nodejs/wbs_rechner_express.js

+ 42 - 16
backend_nodejs/wbs_rechner_express.js

@@ -31,21 +31,24 @@ app.use('/api', swaggerUi.serve, swaggerUi.setup(specs));
  *       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
+ *             type: object
+ *             properties:
+ *               persons:
+ *                 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
@@ -56,10 +59,33 @@ app.use('/api', swaggerUi.serve, swaggerUi.setup(specs));
  *               properties:
  *                 wbsGranted:
  *                   type: boolean
+ *     requestBody:
+ *       description: Example request body
+ *       required: true
+ *       content:
+ *         application/json:
+ *           schema:
+ *             type: object
+ *             example:
+ *               persons:
+ *                 - incomes:
+ *                     - amount: 500
+ *                       frequency: 12
+ *                       advertisingCosts: 500
+ *                     - amount: 200
+ *                       frequency: 1
+ *                       advertisingCosts: 0
+ *                 - incomes:
+ *                     - amount: 1200
+ *                       frequency: 12
+ *                       advertisingCosts: 200
+ *                     - amount: 2000
+ *                       frequency: 1
+ *                       advertisingCosts: 0
  */
 app.post('/calculate', (req, res) => {
     let totalIncome = 0;
-    const persons = req.body;
+    const persons = req.body.persons;
     for (const person of persons) {
         for (const income of person.incomes) {
             let annualIncome = income.amount * income.frequency;