Files
LivePoll/backend/src/routes/v1/poll.route.js
Manik Maity 2f3a9b3e2a Added doc
2024-11-12 19:54:09 +05:30

160 lines
4.0 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import express from "express";
import { verifyToken } from "../../middlwares/verifyToken.js";
import { createPollController, createVoteController, deletePollController, getAllCreatedPollsController, getPollDataController } from "../../controllers/poll.controller.js";
import pollDataSchema from "../../validations/pollDataValidation.js";
import validator from "../../validations/validator.js";
import voteSchema from "../../validations/voteValidation.js";
const pollRouter = express.Router();
/**
* @swagger
* /poll/test:
* get:
* summary: Test route for poll
* tags: [Poll]
* responses:
* 200:
* description: Success
*/
pollRouter.get("/test", (req, res) => {
res.json({
success : true,
message : "Poll route is working✔"
})
})
/**
* @swagger
* /poll/create:
* post:
* summary: Create poll
* tags: [Poll]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* title:
* type: string
* description:
* type: string
* options:
* type: array
* items:
* type: string
* required:
* - title
* - description
* - options
* responses:
* 201:
* description: Poll created successfully
* 400:
* description: Validation error
* 401:
* description: Unauthorized
* 500:
* description: Internal server error
*
*/
pollRouter.post("/create", validator(pollDataSchema), verifyToken, createPollController);
/**
* @swagger
* /poll/data/{pollId}:
* get:
* summary: Get poll data
* tags: [Poll]
* parameters:
* - in: path
* name: pollId
* schema:
* type: string
* required: true
* description: Poll ID
* responses:
* 200:
* description: Poll data fetched successfully
* 401:
* description: Unauthorized
* 500:
* description: Internal server error
*/
pollRouter.get("/data/:pollId", verifyToken, getPollDataController);
/**
* @swagger
* /poll/created:
* get:
* summary: Get all created polls
* tags: [Poll]
* responses:
* 200:
* description: All created polls fetched successfully
* 401:
* description: Unauthorized
* 500:
* description: Internal server error
*/
pollRouter.get("/created", verifyToken, getAllCreatedPollsController);
/**
* @swagger
* /poll/delete/{pollId}:
* delete:
* summary: Delete poll
* tags: [Poll]
* parameters:
* - in: path
* name: pollId
* schema:
* type: string
* required: true
* description: Poll ID
* responses:
* 200:
* description: Poll deleted successfully
* 401:
* description: Unauthorized
* 500:
* description: Internal server error
* */
pollRouter.delete("/delete/:pollId", verifyToken, deletePollController);
/**
* @swagger
* /poll/vote:
* post:
* summary: Create vote
* tags: [Vote]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* pollId:
* type: string
* optionId:
* type : string
* required:
* - pollId
* - optionId
* responses:
* 201:
* description: Vote created successfully
* 400:
* description: Validation error
* 401:
* description: Unauthorized
* 404:
* description: Poll not found
* 500:
* description: Internal server error
*/
pollRouter.post("/vote", validator(voteSchema), verifyToken, createVoteController);
export default pollRouter;