2024-11-08 20:27:06 +05:30
|
|
|
|
import express from "express";
|
|
|
|
|
|
import { verifyToken } from "../../middlwares/verifyToken.js";
|
2024-11-12 19:47:58 +05:30
|
|
|
|
import { createPollController, createVoteController, deletePollController, getAllCreatedPollsController, getPollDataController } from "../../controllers/poll.controller.js";
|
2024-11-08 20:27:06 +05:30
|
|
|
|
import pollDataSchema from "../../validations/pollDataValidation.js";
|
|
|
|
|
|
import validator from "../../validations/validator.js";
|
2024-11-12 19:47:58 +05:30
|
|
|
|
import voteSchema from "../../validations/voteValidation.js";
|
2024-11-08 20:27:06 +05:30
|
|
|
|
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);
|
2024-11-09 22:07:17 +05:30
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @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
|
|
|
|
|
|
*/
|
2024-11-09 21:18:01 +05:30
|
|
|
|
pollRouter.get("/data/:pollId", verifyToken, getPollDataController);
|
2024-11-09 22:07:17 +05:30
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @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
|
|
|
|
|
|
*/
|
2024-11-09 21:18:01 +05:30
|
|
|
|
pollRouter.get("/created", verifyToken, getAllCreatedPollsController);
|
2024-11-09 20:53:28 +05:30
|
|
|
|
|
2024-11-10 15:44:02 +05:30
|
|
|
|
/**
|
|
|
|
|
|
* @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
|
|
|
|
|
|
* */
|
2024-11-09 22:31:19 +05:30
|
|
|
|
pollRouter.delete("/delete/:pollId", verifyToken, deletePollController);
|
|
|
|
|
|
|
2024-11-12 19:54:09 +05:30
|
|
|
|
/**
|
|
|
|
|
|
* @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
|
|
|
|
|
|
*/
|
2024-11-12 19:47:58 +05:30
|
|
|
|
pollRouter.post("/vote", validator(voteSchema), verifyToken, createVoteController);
|
|
|
|
|
|
|
2024-11-08 20:27:06 +05:30
|
|
|
|
export default pollRouter;
|