Source: routes/eventRoutes.js

  1. /**
  2. * @fileoverview Routes for Event Management in Satoshi Showdown.
  3. * This module defines the Express routes for handling event-related operations
  4. * such as creating, updating, deleting, and retrieving events. Each route is
  5. * associated with a specific controller function to handle the request.
  6. * These routes are integral to the application's RESTful API, allowing clients
  7. * to interact with event data stored in the backend system.
  8. *
  9. * @module routes/eventRoutes
  10. * @requires express - Express framework to define routes.
  11. * @requires controllers/eventController - Controller functions for event operations.
  12. */
  13. const express = require("express");
  14. const {
  15. authorizeUser,
  16. authorizeAdmin,
  17. } = require("../middlewares/jwtAuthorizeMiddleware");
  18. const {
  19. handleCreateEvent,
  20. handleUpdateEvent,
  21. handleDeleteEvent,
  22. handleGetEvent,
  23. handleGetAllEvents,
  24. handleJoinEvent,
  25. handleSettleEvent,
  26. handleCastVote,
  27. handleDetermineOutcome,
  28. handleAwardWinner,
  29. handleRefundUser,
  30. } = require("../controllers/eventController");
  31. const router = new express.Router();
  32. /**
  33. * POST route to create a new event in the system.
  34. * This route invokes the handleCreateEvent controller to process the event creation request.
  35. * It expects the event data to be provided in the request body, typically including details
  36. * like event name, date, location, and other relevant information.
  37. *
  38. * @name post/create
  39. * @function
  40. * @memberof module:routes/eventRoutes
  41. * @inner
  42. * @param {string} path - Express path.
  43. * @param {callback} middleware - Express middleware (controller function).
  44. * @access Public/Private (depending on your application's requirement)
  45. */
  46. router.post("/create", authorizeUser, handleCreateEvent);
  47. /**
  48. * PUT route to update an existing event identified by its ID.
  49. * This route calls the handleUpdateEvent controller to handle the event update request.
  50. * The event ID is expected as a URL parameter, and the updated event data should be
  51. * provided in the request body.
  52. *
  53. * @name put/update
  54. * @function
  55. * @memberof module:routes/eventRoutes
  56. * @inner
  57. * @param {string} path - Express path with event ID as a parameter.
  58. * @param {callback} middleware - Express middleware (controller function).
  59. * @access Public/Private (depending on your application's requirement)
  60. */
  61. router.put("/update/:id", handleUpdateEvent);
  62. /**
  63. * DELETE route to remove an event from the system based on its ID.
  64. * This route utilizes the handleDeleteEvent controller to process the event deletion request.
  65. * The event ID to delete is expected as a URL parameter.
  66. *
  67. * @name delete/delete
  68. * @function
  69. * @memberof module:routes/eventRoutes
  70. * @inner
  71. * @param {string} path - Express path with event ID as a parameter.
  72. * @param {callback} middleware - Express middleware (controller function).
  73. * @access Public/Private (depending on your application's requirement)
  74. */
  75. router.delete("/delete/:id", handleDeleteEvent);
  76. /**
  77. * GET route to retrieve detailed information about a specific event by its ID.
  78. * This route uses the handleGetEvent controller to fetch and return the requested event data.
  79. * The event ID is expected as a URL parameter, and the route returns the full details
  80. * of the specified event if found.
  81. *
  82. * @name get/get
  83. * @function
  84. * @memberof module:routes/eventRoutes
  85. * @inner
  86. * @param {string} path - Express path with event ID as a parameter.
  87. * @param {callback} middleware - Express middleware (controller function).
  88. * @access Public/Private (depending on your application's requirement)
  89. */
  90. router.get("/get/:id", handleGetEvent);
  91. /**
  92. * GET route to retrieve a list of all events in the system.
  93. * This route calls the handleGetAllEvents controller to fetch and return data for all events.
  94. * It is typically used to display an overview of events or for administrative purposes.
  95. *
  96. * @name get/getAll
  97. * @function
  98. * @memberof module:routes/eventRoutes
  99. * @inner
  100. * @param {string} path - Express path.
  101. * @param {callback} middleware - Express middleware (controller function).
  102. * @access Public/Private (depending on your application's requirement)
  103. */
  104. router.get("/getAll", handleGetAllEvents);
  105. /**
  106. * POST route for a user to join an event.
  107. * Expects event and user IDs in the request body.
  108. *
  109. * @name post/join
  110. * @function
  111. * @memberof module:routes/eventRoutes
  112. * @inner
  113. * @param {string} path - Express path.
  114. * @param {callback} middleware - Express middleware (controller function).
  115. * @access Public/Private (as required)
  116. */
  117. router.post("/join", authorizeUser, handleJoinEvent);
  118. /**
  119. * POST route to settle an event.
  120. * Expects the event ID as a URL parameter.
  121. *
  122. * @name post/settle
  123. * @function
  124. * @memberof module:routes/eventRoutes
  125. * @inner
  126. * @param {string} path - Express path with event ID as a parameter.
  127. * @param {callback} middleware - Express middleware (controller function).
  128. * @access Public/Private (as required)
  129. */
  130. router.post("/settle/:eventId", authorizeUser, handleSettleEvent);
  131. /**
  132. * POST route to cast a vote for a user.
  133. * Expects the user ID and vote data in the request body.
  134. *
  135. * @name post/vote
  136. * @function
  137. * @memberof module:routes/eventRoutes
  138. * @inner
  139. * @param {string} path - Express path.
  140. * @param {callback} middleware - Express middleware (controller function).
  141. * @access Public/Private (as required)
  142. */
  143. router.post("/vote", authorizeUser, handleCastVote);
  144. /**
  145. * POST route to determine the outcome of an event.
  146. * This route calls the handleDetermineOutcome controller to process the event outcome determination.
  147. * The event ID is expected as a URL parameter.
  148. *
  149. * @name post/outcome
  150. * @function
  151. * @memberof module:routes/eventRoutes
  152. * @inner
  153. * @param {string} path - Express path with event ID as a parameter.
  154. * @param {callback} middleware - Express middleware (controller function).
  155. * @access Public/Private (depending on your application's requirement)
  156. */
  157. router.post("/outcome/:eventId", authorizeUser, handleDetermineOutcome);
  158. /**
  159. * POST route to award the winner of an event.
  160. * This route is used to process the prize distribution for the winner of a specified event.
  161. *
  162. * @name post/awardWinner
  163. * @function
  164. * @memberof module:routes/eventRoutes
  165. * @inner
  166. * @param {string} path - Express path with event ID as a parameter.
  167. * @param {callback} middleware - Express middleware (controller function).
  168. * @access Private (Admins or authorized personnel only)
  169. */
  170. router.post("/award/:eventId", authorizeUser, handleAwardWinner);
  171. router.post("/refund", handleRefundUser);
  172. module.exports = router;