HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/good-life-be/api/Questions/index.js
// routes.js
import express from 'express';
import {
  getDaysCount,
  getFormDatas,
  postFormDatas,
  getUserFormData,
  updateUserFormData,
  tempFormDataCreationHandler,
} from './controller.js';

const router = express.Router();

router.get('/', getFormDatas);
/**
 * @swagger
 * /api/form:
 *   get:
 *     summary: Get form data filtered by subcategoryId and/or categoryId
 *     tags:
 *       - Form Data
 *     parameters:
 *       - in: query
 *         name: subcategoryId
 *         schema:
 *           type: integer
 *         required: false
 *         description: ID of the subcategory to filter form data
 *       - in: query
 *         name: categoryId
 *         schema:
 *           type: integer
 *         required: false
 *         description: ID of the category to filter form data
 *     responses:
 *       '200':
 *         description: Successfully retrieved form data
 *         content:
 *           application/json:
 *             schema:
 *               type: array
 *               items:
 *                 type: object
 *                 properties:
 *                   id:
 *                     type: integer
 *                   question:
 *                     type: string
 *                   answer:
 *                     type: object
 *                     additionalProperties: true
 *                   answer_type:
 *                     type: string
 *                   createdAt:
 *                     type: string
 *                     format: date-time
 *                   updatedAt:
 *                     type: string
 *                     format: date-time
 */

router.get('/daysCount', getDaysCount);

router.post('/', postFormDatas);
/**
 * @swagger
 * /api/form:
 *   post:
 *     summary: Post questions and their answers to the event system and create records in the Event model
 *     tags:
 *       - Form Data
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *     responses:
 *       '200':
 *         description: Successfully posted questions and processed events.
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                   description: Indicates if the operation was successful.
 *                   example: true
 *                 data:
 *                   type: object
 *                   description: The response data from the external API after posting the questions.
 *                   additionalProperties: true
 *       '400':
 *         description: Invalid input or request body.
 *       '500':
 *         description: Server error while processing the request.
 */

router.get('/view', getUserFormData);
/**
 * @swagger
 * /api/form/view:
 *   get:
 *     summary: Retrieve submitted form data
 *     tags:
 *       - Form Data
 *     parameters:
 *       - in: query
 *         name: categoryId
 *         required: true
 *         schema:
 *           type: integer
 *         description: ID of the category (required).
 *       - in: query
 *         name: subCategoryId
 *         required: false
 *         schema:
 *           type: integer
 *         description: ID of the subcategory (optional).
 *     responses:
 *       '200':
 *         description: Successfully retrieved form data.
 *       '400':
 *         description: Bad request.
 *       '500':
 *         description: Internal server error.
 */

router.put('/', updateUserFormData);
/**
 * @swagger
 * /api/form:
 *   put:
 *     summary: Update user submitted form data
 *     tags:
 *       - Form Data
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               userData:
 *                 type: object
 *                 description: The form data submitted by the user.
 *     responses:
 *       '200':
 *         description: Successfully updated form data.
 *       '400':
 *         description: Bad request.
 *       '500':
 *         description: Internal server error.
 */

router.post('/temp', tempFormDataCreationHandler);
/**
 * @swagger
 * /api/form/temp:
 *   post:
 *     summary: Store temporary form data
 *     description: Saves the form data submitted by the user as a temporary record.
 *     tags:
 *       - Form Data
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               categoryId:
 *                 type: integer
 *                 description: The ID of the category.
 *                 example: 1
 *               subcategoryId:
 *                 type: integer
 *                 description: The ID of the subcategory (optional).
 *                 example: 10
 *               userData:
 *                 type: object
 *                 description: The submitted form data.
 *     responses:
 *       '200':
 *         description: Form data saved successfully.
 *       '400':
 *         description: Invalid request data.
 *       '500':
 *         description: Error occurred while processing the request.
 */

export default router;