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/Event/index.js
import express from 'express';
import {
  addEvent,
  deleteEvent,
  deleteEvents,
  downloadPDF,
  editEvent,
  listEvents,
  totalConflicts,
  updateShowAndHideEvent,
} from './controller.js';
import {
  editEventValidator,
  validateEventId,
  validateEventQuery,
} from './validator.js';

const router = express.Router();

/**
 * @swagger
 * components:
 *   schemas:
 *     Event:
 *       type: object
 *       properties:
 *         event_title:
 *           type: string
 *           description: Title of the event
 *         event_description:
 *           type: string
 *           description: Description of the event
 *         event_name:
 *           type: string
 *           description: Name of the event
 *         date:
 *           type: string
 *           format: date
 *           description: Date of the event (e.g., 2025-01-09)
 *         start_time:
 *           type: string
 *           description: Start time of the event
 *         end_time:
 *           type: string
 *           description: End time of the event
 *         category:
 *           type: string
 *           description: Category of the event
 *         subCategory:
 *           type: string
 *           description: Subcategory of the event
 */

router.get('/', listEvents);
/**
 * @swagger
 * /api/event:
 *   get:
 *     tags:
 *       - Event
 *     security:
 *       - bearerAuth: []
 *     summary: List all events for calendar view
 *     responses:
 *       201:
 *         description: Event created successfully
 *       400:
 *         description: Bad request (invalid data)
 *       500:
 *         description: Internal server error
 */

router.post('/', addEvent);
/**
 * @swagger
 * /api/event:
 *   post:
 *     tags:
 *       - Event
 *     security:
 *       - bearerAuth: []
 *     summary: Create a new event
 *     description: This API creates a new event based on the provided details.
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             $ref: '#/components/schemas/Event'
 *     responses:
 *       201:
 *         description: Event created successfully
 *       400:
 *         description: Bad request (invalid data)
 *       500:
 *         description: Internal server error
 */

router.get('/calendar-pdf', downloadPDF);
/**
 * @swagger
 * /api/event/calendar-pdf:
 *   get:
 *     tags:
 *       - Event
 *     security:
 *       - bearerAuth: []
 *     summary: PDF download
 *     responses:
 *       200:
 *         description: Event deleted successfully
 *       404:
 *         description: Event not found
 *       500:
 *         description: Internal server error
 */

router.get('/conflicts-count', totalConflicts);
/**
 * @swagger
 * /api/event/conflicts-count:
 *   get:
 *     tags:
 *       - Event
 *     security:
 *       - bearerAuth: []
 *     summary: Conflicts count
 *     responses:
 *       200:
 *         description: Conflict count fetched
 *       404:
 *         description: Event not found
 *       500:
 *         description: Internal server error
 */

router.delete('/:id', validateEventId, validateEventQuery, deleteEvent);
/**
 * @swagger
 * /api/event/{id}:
 *   delete:
 *     tags:
 *       - Event
 *     security:
 *       - bearerAuth: []
 *     summary: Delete an event by ID
 *     description: This endpoint deletes an event from the database using its unique ID.
 *     parameters:
 *       - name: id
 *         in: path
 *         description: The ID of the event to delete
 *         required: true
 *         schema:
 *           type: string
 *       - name: type
 *         in: query
 *         description: The type of deletion ('all' or 'selected')
 *         required: true
 *         schema:
 *           type: string
 *           enum: [all, selected]
 *     responses:
 *       200:
 *         description: Event deleted successfully
 *       404:
 *         description: Event not found
 *       500:
 *         description: Internal server error
 */

router.put(
  '/:id',
  validateEventId,
  validateEventQuery,
  editEventValidator,
  editEvent
);
/**
 * @swagger
 * /api/event/{id}:
 *   put:
 *     summary: Edit an existing event
 *     description: Updates the details of an existing event based on the provided ID and request body.
 *     tags:
 *       - Event
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - name: id
 *         in: path
 *         description: The ID of the event to delete
 *         required: true
 *         schema:
 *           type: string
 *       - name: type
 *         in: query
 *         description: The type of deletion ('all' or 'selected')
 *         required: true
 *         schema:
 *           type: string
 *           enum: [all, selected]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             $ref: '#/components/schemas/Event'
 *     responses:
 *       200:
 *         description: Event updated successfully
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                   example: true
 *                 message:
 *                   type: string
 *                   example: Event updated successfully
 *       400:
 *         description: Invalid request or event not found
 *       500:
 *         description: Internal server error
 */

router.put('/hide-show/:id', updateShowAndHideEvent);
/**
 * @swagger
 * /api/event/hide-show/{id}:
 *   put:
 *     summary: Update visibility of an event
 *     description: Hides or shows an event by updating the `is_visible` property.
 *     tags:
 *       - Event
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - name: id
 *         in: path
 *         description: ID of the event to update
 *         required: true
 *         schema:
 *           type: string
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               is_visible:
 *                 type: boolean
 *                 description: The visibility status of the event.
 *     responses:
 *       200:
 *         description: Event visibility updated successfully
 *       400:
 *         description: Invalid input
 *       404:
 *         description: Event not found
 *       500:
 *         description: Internal server error
 */

router.delete('/', deleteEvents);

export default router;